L
logpie
Unregistered / Unconfirmed
GUEST, unregistred user!
server用了重叠IO
作为测试用
我在client发送一个integer : ret:=send(CliSocket,Pchar(aa),4,0);
下面是server的接收线程
bufferchar;
while true do
begin
// Application.ProcessMessages ;
SAccept:=accept(SListen,tmpAdd,size);
Fstr:='Accept';
synchronize(setmsg);
EventArray[EventTotal]:=WSACreateEvent();
Zeromemory(@overlap,sizeof(overlap));
Overlap.hEvent :=EventArray[EventTotal];
new(buffer);
Databuf.len :=4;
Databuf.buf:=buffer;
inc(EventTotal);
WSARecv(SAccept,@DataBuf,1,bufRecvd,Flags,@OverLap,nil);
while true do
begin
Index:=WSAWaitForMultipleEvents(EventTotal,@EventArray,false,WSA_INFINITE,false);
WSAResetEvent(EventArray[index - WSA_WAIT_Event_0]);
WSAGetOverLappedResult(SAccept,@OverLap,@byts,false,Flags);
if byts=0 then
begin
Fstr:='Closing...';
Synchronize(setmsg);
closeSocket(SAccept);
WSACloseEvent(EventArray[index-WSA_WAIT_EVENT_0]);
end;
lala:=integer(DataBuf.buf);//!!!!!!!!!!!!!!!!!!!!!!!!!
Fstr:=inttostr(lala);
// FStr:=databuf.buf;
Synchronize(setmsg);
Flags:=0;
ZeroMemory(@OverLap,sizeof(overlap));
OverLap.hEvent :=EventArray[index - WSA_WAIT_EVENT_0];
new(buffer);
Databuf.len :=4;
Databuf.buf :=buffer;
WSARecv(SAccept,@Databuf,1,bufRecvd,Flags,@overlap,nil);
end;
end;
但是server里lala并没有接受到client发过来的值,且buffer也为空
client,server都已建立起正确的连接
我在client发送一个string,定义buffer:aaray[0..xxx] of char 时server就可以正确接受
这是为什么?
作为测试用
我在client发送一个integer : ret:=send(CliSocket,Pchar(aa),4,0);
下面是server的接收线程
bufferchar;
while true do
begin
// Application.ProcessMessages ;
SAccept:=accept(SListen,tmpAdd,size);
Fstr:='Accept';
synchronize(setmsg);
EventArray[EventTotal]:=WSACreateEvent();
Zeromemory(@overlap,sizeof(overlap));
Overlap.hEvent :=EventArray[EventTotal];
new(buffer);
Databuf.len :=4;
Databuf.buf:=buffer;
inc(EventTotal);
WSARecv(SAccept,@DataBuf,1,bufRecvd,Flags,@OverLap,nil);
while true do
begin
Index:=WSAWaitForMultipleEvents(EventTotal,@EventArray,false,WSA_INFINITE,false);
WSAResetEvent(EventArray[index - WSA_WAIT_Event_0]);
WSAGetOverLappedResult(SAccept,@OverLap,@byts,false,Flags);
if byts=0 then
begin
Fstr:='Closing...';
Synchronize(setmsg);
closeSocket(SAccept);
WSACloseEvent(EventArray[index-WSA_WAIT_EVENT_0]);
end;
lala:=integer(DataBuf.buf);//!!!!!!!!!!!!!!!!!!!!!!!!!
Fstr:=inttostr(lala);
// FStr:=databuf.buf;
Synchronize(setmsg);
Flags:=0;
ZeroMemory(@OverLap,sizeof(overlap));
OverLap.hEvent :=EventArray[index - WSA_WAIT_EVENT_0];
new(buffer);
Databuf.len :=4;
Databuf.buf :=buffer;
WSARecv(SAccept,@Databuf,1,bufRecvd,Flags,@overlap,nil);
end;
end;
但是server里lala并没有接受到client发过来的值,且buffer也为空
client,server都已建立起正确的连接
我在client发送一个string,定义buffer:aaray[0..xxx] of char 时server就可以正确接受
这是为什么?