给你个最简单的:
TReadThread = class(TThread)
protected
RcvBuf: string;
procedure NotifyRead;
procedure Execute;
override;
end;
procedure TReadThread.Execute;
var
l: Integer;
begin
setlength(Rcvbuf, 1);
while truedo
begin
if recv(form1.clientsocket1.socket.sockethandle, Rcvbuf[1], 1, 0) = SOCKET_ERROR then
break;
if ioctlsocket(form1.clientsocket1.socket.sockethandle, FIONREAD, l)=SOCKET_ERROR then
break;
setlength(Rcvbuf, l+1);
if recv(form1.clientsocket1.socket.sockethandle, Rcvbuf[2], l, 0)=SOCKET_ERROR then
break;
synchronize(notifyread);
end;
end;
procedure TReadThread.NotifyRead;
begin
form1.memo1.lines.add(Rcvbuf);
end;