代码拉取完成,页面将自动刷新
uses
sockets, windows;
procedure recv(psocket:pointer);stdcall;
var
buffer:array[0..1024] of byte;
socket: ^longint;
len:integer;
remsg:pchar;
begin
socket:=psocket;
remsg:=pchar(@buffer);
while true do begin
len:=fprecv(socket^,@buffer,1024,0);
if(len>0)then begin
buffer[len]:=0;
write('Received:');
writeln(remsg);
end;
end;
end;
var
serverSocket, clientSocket: longint;
server_addr, client_addr: TInetSockAddr;
iaddr,port:longint;
tid:longword;
buf:array[0..2048] of char;
i:integer;
begin
serverSocket:=fpSocket( AF_INET, SOCK_STREAM, 0);
writeln('Input port:');
readln(port);
server_addr.sin_family:=AF_INET;
server_addr.sin_port:=htons(port);
server_addr.sin_addr.s_addr:=0;
fpbind(serverSocket, @server_addr, sizeof(server_addr));
fplisten(serverSocket,0);
iaddr:=sizeof(client_addr);
writeln('Waiting for connect...');
clientSocket:=fpaccept(serverSocket,@client_addr,@iaddr);
writeln('Connect successed!Now talking:');
CreateThread(nil,0,@recv,@clientSocket,0,tid);
while true do begin
i:=0;
while not eoln do begin
read(buf[i]);
inc(i);
end;
readln;
fpsend(clientSocket,@buf,i,0);
end;
end.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。