A
acee
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Server3;
var
s,newsock:TSocket;
addrs:TSockAddrIn;
addrcSockAddr;
leng:Integer;
wsa:WSAData;
wVersionRequested:WORD;
buf:array[0..128]of char;
buf2:array[0..128]of char;
begin
wVersionRequested := MAKEWORD( 2, 0 );
WSAStartup(wVersionRequested,wsa);
s := socket(AF_INET,SOCK_STREAM,0);
Memo1.Lines.Add('Create Socket Succeed');
addrs.sin_family := AF_INET;
addrs.sin_addr.S_addr := htonl(INADDR_ANY);
addrs.sin_port := htons(12000);
bind(s,addrs,sizeof(addrs));
Memo1.Lines.Add('Bind Socket Succeed');
listen(s,1);
Memo1.Lines.Add('Listen Socket Succeed');
while 1>0 do
begin
leng:= sizeof(addrc);
newsock := accept(s,addrc,@leng);
if newsock >= 0 then
Memo1.Lines.Add('Accept Socket='+ InttoStr(newsock)+ 'succeed!');
if recv(newsock,buf,sizeof(buf),0)>0 then
begin
Form1.Memo1.Lines.Add(buf2);
strcopy(buf2,PChar(form1.Edit1.Text));
send(newsock,buf2,sizeof(buf2),0);
end;
closesocket(newsock);
end;
Closesocket(s);
WSACleanup();
sleep(2000);
end;
在代码 newsock := accept(s,addrc,@leng);处为何没有阻塞等到客户端的连接?请高手指点。谢谢!
var
s,newsock:TSocket;
addrs:TSockAddrIn;
addrcSockAddr;
leng:Integer;
wsa:WSAData;
wVersionRequested:WORD;
buf:array[0..128]of char;
buf2:array[0..128]of char;
begin
wVersionRequested := MAKEWORD( 2, 0 );
WSAStartup(wVersionRequested,wsa);
s := socket(AF_INET,SOCK_STREAM,0);
Memo1.Lines.Add('Create Socket Succeed');
addrs.sin_family := AF_INET;
addrs.sin_addr.S_addr := htonl(INADDR_ANY);
addrs.sin_port := htons(12000);
bind(s,addrs,sizeof(addrs));
Memo1.Lines.Add('Bind Socket Succeed');
listen(s,1);
Memo1.Lines.Add('Listen Socket Succeed');
while 1>0 do
begin
leng:= sizeof(addrc);
newsock := accept(s,addrc,@leng);
if newsock >= 0 then
Memo1.Lines.Add('Accept Socket='+ InttoStr(newsock)+ 'succeed!');
if recv(newsock,buf,sizeof(buf),0)>0 then
begin
Form1.Memo1.Lines.Add(buf2);
strcopy(buf2,PChar(form1.Edit1.Text));
send(newsock,buf2,sizeof(buf2),0);
end;
closesocket(newsock);
end;
Closesocket(s);
WSACleanup();
sleep(2000);
end;
在代码 newsock := accept(s,addrc,@leng);处为何没有阻塞等到客户端的连接?请高手指点。谢谢!