我把代码帖一下,大家帮我看看
Procedure TServerThread.ClientExecute;
Var
Data: Array[0..1023] Of char;
RecText, LastText, sendecho: String;
SocketStream: TWinSocketStream;
b:boolean;
Begin
inherited FreeOnTerminate := True;
CoInitialize(nil);
While (Not Terminated) And (ClientSocket.Connected) Do
Try
SocketStream := TWinSocketStream.Create(ClientSocket, 30000); //30秒延时
Try
FillChar(Data, SizeOf(Data), 0); //每次处理1024字节
If SocketStream.Read(Data, SizeOf(Data)) = 0 Then Begin //接收数据为空
ClientSocket.SendText('TimeOut on Server'+CRLF);
sleep(1);
ClientSocket.Close;
Terminate;
End;
RecText := Data;
If ClientSocket.Connected Then Begin //正常的处理
sleep(1);
b:=false;
//**************************** protocol ******************************************//
{此处处理协议部分}
//**************************** protocol ******************************************//
ClientSocket.SendText(sendecho);
if b = true then begin //接受close命令后 b=true
sleep(1);
ClientSocket.Close;
Terminate;
end;
End;
Finally
SocketStream.Free;
End;
Except
//HandleException;
ClientSocket.Close;
Terminate;
End;
CoUninitialize;
End;