D
dgidqs
Unregistered / Unconfirmed
GUEST, unregistred user!
服务端程序是这样的
/////////////////////////////////////////////////////////////
function mainThreadFun(lpointer):integer;
var
port,size:integer;
thd,pid:dword;
WSADATA:TWSADATA;
sin:TSockAddr;
ss:TSocket;
pcs:^TSocket;
databuf:array[0..MaxLen] of char;
function ThreadFun(lpointer):integer;stdcall;
var
pcs:^TSocket;
ret:integer;
begin
Result:=0;
pcs:=lp;
ret:=recv(pcs^,databuf,MaxLen,0);
databuf[ret]:=#0;
showmessage(strpas(databuf));
closesocket(pcs^);
Dispose(pcs);
end;
begin
WSAStartup(MakeWord(1,1),WSADATA);
ss:=socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
port:=7404;
sin.sin_family:=PF_INET;
sin.sin_port:=htons(port);
bind(ss,sin,sizeof(sin));
listen(ss,5);
repeat
size:=SizeOf(sin);
new(pcs);
pcs^:=accept(ss,@sin,@size);
thd:=CreateThread(nil,0,@ThreadFun,pcs,0,pid);
WaitForSingleObject(thd,INFINITE);
until false;
closesocket(ss);
WSACleanup;
end;
////////////////////////////////////////////////////////////
然后客户端我用 ClientSocket控件 发送字符串
ClientSocket1.Socket.SendText('111');
为什么服务端只能接受一次,然后就不行了呢????
/////////////////////////////////////////////////////////////
function mainThreadFun(lpointer):integer;
var
port,size:integer;
thd,pid:dword;
WSADATA:TWSADATA;
sin:TSockAddr;
ss:TSocket;
pcs:^TSocket;
databuf:array[0..MaxLen] of char;
function ThreadFun(lpointer):integer;stdcall;
var
pcs:^TSocket;
ret:integer;
begin
Result:=0;
pcs:=lp;
ret:=recv(pcs^,databuf,MaxLen,0);
databuf[ret]:=#0;
showmessage(strpas(databuf));
closesocket(pcs^);
Dispose(pcs);
end;
begin
WSAStartup(MakeWord(1,1),WSADATA);
ss:=socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
port:=7404;
sin.sin_family:=PF_INET;
sin.sin_port:=htons(port);
bind(ss,sin,sizeof(sin));
listen(ss,5);
repeat
size:=SizeOf(sin);
new(pcs);
pcs^:=accept(ss,@sin,@size);
thd:=CreateThread(nil,0,@ThreadFun,pcs,0,pid);
WaitForSingleObject(thd,INFINITE);
until false;
closesocket(ss);
WSACleanup;
end;
////////////////////////////////////////////////////////////
然后客户端我用 ClientSocket控件 发送字符串
ClientSocket1.Socket.SendText('111');
为什么服务端只能接受一次,然后就不行了呢????