TTcpServer、TTcpClient通讯例程

时间:2021-02-01 04:58:37
【文件属性】:

文件名称:TTcpServer、TTcpClient通讯例程

文件大小:396KB

文件格式:ZIP

更新时间:2021-02-01 04:58:37

TcpServer

procedure TForm1.btnActivateListenClick(Sender: TObject); begin TcpServer1.LocalHost := edtRemoteHost.Text; TcpServer1.LocalPort := edtLocalPort.Text; TcpServer1.Active := True; end; procedure TForm1.btnSendClick(Sender: TObject); var i:Integer; begin TcpClient1.RemoteHost := edtRemoteHost.Text; TcpClient1.RemotePort := edtRemotePort.Text; try TcpClient1.Connect; for i:=0 to mmSend.Lines.Count -1 do TcpClient1.Sendln(mmSend.Lines[i]); finally TcpClient1.Disconnect; end end; procedure TForm1.TcpServer1Accept(Sender: TObject; ClientSocket: TCustomIpClient); var s :string; DataThread: TClientDataThread; begin DataThread := TClientDataThread.Create(True); DataThread := TClientDataThread.Create(True); DataThread.TargetList := mmReceive.Lines; DataThread.ListBuffer.Add('**Connection Accepted***'); DataThread.ListBuffer.Add('Remote Host:' + ClientSocket.LookupHostName(ClientSocket.RemoteHost) + '(' + ClientSocket.RemoteHost + ')'); DataThread.ListBuffer.Add('===== Begin message ====='); s := ClientSocket.Receiveln; while s<> '' do begin DataThread.ListBuffer.Add(s); s := ClientSocket.Receiveln; end; DataThread.ListBuffer.Add('====End of nessage ===='); DataThread.Resume; end;


【文件预览】:
Server2
----MainForm.pas(2KB)
----MainForm.~dfm(2KB)
----__history()
--------MainForm.pas.~1~(2KB)
--------MainForm.dfm.~3~(3KB)
--------MainForm.dfm.~2~(3KB)
--------MainForm.dfm.~1~(2KB)
--------MainForm.pas.~2~(2KB)
----Exa08_01.dpr(227B)
----untThread.pas(956B)
----MainForm.~ddp(55B)
----MainForm.~pas(2KB)
----Exa08_01.cfg(390B)
----untThread.~pas(1KB)
----Exa08_01.identcache(137B)
----Exa08_01.dproj(4KB)
----MainForm.ddp(55B)
----MainForm.dcu(8KB)
----Exa08_01.res(876B)
----Exa08_01.dof(2KB)
----Exa08_01.~dpr(194B)
----untThread.dcu(2KB)
----Exa08_01.exe(857KB)
----Exa08_01.dproj.local(62B)
----MainForm.dfm(3KB)

网友评论