procedure TMyThread.Execute;
var
Buffer: array [0..BufferLength] of Char;
lenNeed: Integer;
lenRead: Integer;
FSocketStream: TWinSocketStream;
begin
while (not Terminated) and FClientSocket.Socket.Connected do
begin
try
FSocketStream := TWinSocketStream.Create( FClientSocket.Socket, 60000);
try
{ initialize the buffer }
FillChar(Buffer, BufferLength, 0);
{ give the client 60 seconds to start writing }
if FSocketStream.WaitForData(60000) then
begin
lenNeed := BufferLength;
lenRead := FSocketStream.Read(Buffer, lenNeed);
if lenRead = 0 then
begin
Self.ClientSocket.Close;
end else
begin
// ClientSocket.SendText( Buffer );
Buffer[lenRead+1] := #0;
// 处理接收的数据
end;
end else
Self.ClientSocket.Close;
finally
FSocketStream.Free;
end;
except
(*
if not(ExceptObject is EAbort) then
Synchronize(HandleThreadException);
*)
// HandleException;
end;
end;