2,"同步"指提交一个SOCKET请求之后,直到系统完成操作或超时后才返回
的方式."异步"指提交SOCKET请求之后马上返回,系统在后台进行真正
的操作,当操作完成后向程序发送消息的方式.不建议采用同步方式
3,下面这个函数看对你有帮助没,
Cs: TClientSocket;
procedure TCsObject.CsWait;
var
pm: PMsgPack;
p: pointer;
Stream: TWinSocketStream;
begin
while CS.Socket.Connected do
begin
try
Stream := TWinSocketStream.Create(CS.Socket, 60000);
pm := AllocMem(MSGHEADERSIZE); { initialize the buffer }
try
{ give the client 60 seconds to start writing }
if Stream.WaitForData(60000) then
begin
Stream.ReadBuffer(pm^, MSGHEADERSIZE);
p := AllocMem(pm^.Length);
try
Stream.ReadBuffer(p^, pm^.Length);
case pm^.MsgType of
{ now process the request }
AppMsg_XXFB: Process_AppMsg_XXFB(Cs.Socket, TAppMsg_XXFB(p^));
AppMsg_SvrInfos: Process_APPMsg_SvrInfos(Cs.Socket, TAppMsg_SvrInfos(p^));
APPMSG_DISCONNECT:
begin
CS.Socket.Close;
CS.Close;
Break;
end;
end
finally
FreeMem(p, pm^.Length);
end;
end
else
Cs.Socket.Close;
finally
freemem(pm, MSGHEADERSIZE);
Stream.Free;
end;
except
on E: Exception do
begin
FErrorString := E.Message;
HandleException;
end;
end;
end;
end;