SERVER端用TCPSERVER, MEMO .CLIENT端用TCPCLIENT, MEMO,BUTTON.
procedure Tclient.button1Click(Sender: TObject);
var
i:integer;
begin
try
if tcpclient1.Connect then
for i:=0 to memo1.Lines.Count-1 do
tcpclient1.Sendln(memo1.lines[i]);
finally
tcpclient1.Disconnect;
end;
end;
procedure Tserver.TcpServer1Accept(Sender: TObject;
ClientSocket: TCustomIpClient);
var
s:String;
DataThread:TClientDataThread;
begin
DataThread:=TClientDataThread.create(true);
DataThread.targetlist:=memo1.lines;
DataThread.listbuffer.add('***接受连接***');
DataThread.listbuffer.add('客户端主机'+
clientsocket.lookuphostname(clientsocket.RemoteHost)+
'('+clientsocket.RemoteHost+'),发来消息:');
s:=clientsocket.receiveln;
while s<>'' do
begin
datathread.listbuffer.add(s);
s:=clientsocket.receiveln;
end;
datathread.listbuffer.add('***消息结束***');
datathread.resume;
end;