1 Star 1 Fork 0

镇海中学开源项目组/fpsocket-talk

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
socket_client.pas 1.19 KB
一键复制 编辑 原始数据 按行查看 历史
FPC5719 提交于 2022-02-07 16:06 . 阶段性提交
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.
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Pascal
1
https://gitee.com/zhzxOpenSource/fpsocket-talk.git
git@gitee.com:zhzxOpenSource/fpsocket-talk.git
zhzxOpenSource
fpsocket-talk
fpsocket-talk
master

搜索帮助