1 Star 1 Fork 0

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

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
socket_server.pas 1.14 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
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.
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Pascal
1
https://gitee.com/zhzxOpenSource/fpsocket-talk.git
git@gitee.com:zhzxOpenSource/fpsocket-talk.git
zhzxOpenSource
fpsocket-talk
fpsocket-talk
master

搜索帮助