代码拉取完成,页面将自动刷新
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
server_addr: TInetSockAddr;
locationSocket: longint;
tid:longword;
buf:array[0..2048] of char;
i,port:integer;
address:string;
begin
locationSocket:=fpSocket(AF_INET, SOCK_STREAM, 0);
writeln('Socket:',SocketError);
writeln('Input address:');
readln(address);
writeln('Input port:');
readln(port);
server_addr.sin_family:=AF_INET;
server_addr.sin_port:=htons(port);
server_addr.sin_addr:=StrtoNetAddr(address);
writeln('Connect to server...');
if fpconnect(locationSocket, @server_addr, sizeof(server_addr))=0 then begin
CreateThread(nil,0,@recv,@locationSocket,0,tid);
writeln('Connect successed!Now talking...');
while true do begin
i:=0;
while not eoln do begin
read(buf[i]);
inc(i);
end;
readln;
fpsend(locationSocket,@buf,i,0);
end;
end else
writeln('Connect failed!Error code:',SocketError);
end.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。