begin
try
if not Assigned(SocketStream) then
begin
SocketStream := TWinSocketStream.Create(ClientSocket, 60000);
end;
FillChar(ReceiveBuffer, sizeof(ReceiveBuffer), 0); { initialize the buffer }
{ give the client 5 seconds to start writing }
If SocketStream.WaitForData(5000) Then
Repeat
BytesRead := SocketStream.Read(ReceiveBuffer,SizeOf(ReceiveBuffer));
if BytesRead > 0 then
begin
// ..................
// 处理接收到的数据
end
else
begin
{ if can't read in 6 seconds }
ClientSocket.Close; { close the connection }
end; // if BytesRead > 0
Until Not SocketStream.WaitForData(2000);
finally
SocketStream.Free;
end;
end;