Unit unit1;
Interface
Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, idbasecomponent, idcomponent, idtcpserver, stdctrls;
Type
Tform1 = Class (tform)
Idtcpserver1: tidtcpserver;
Button1: tbutton;
Edit1: tedit;
Edit2: tedit;
Label1: tlabel;
Label2: tlabel;
Button2: tbutton;
Procedure button1click (Sender: tobject );
Procedure idtcpserver1execute (athread: tidpeerthread );
Procedure button2click (Sender: tobject );
Private
{Private Declarations}
Public
{Public declarations}
End;
VaR
Form1: tform1;
Implementation
{$ R *. DFM}
Procedure tform1.button1click (Sender: tobject );
Begin
Idtcpserver1.bindings. Clear;
Idtcpserver1.bindings. Add. IP: = '192. 168.1.126 ';
Idtcpserver1.bindings. Add. Port: = 168;
Idtcpserver1.active: = true;
If idtcpserver1.active then
// Showmessage ('server running ')
Edit1.text: = 'server running'
Else
Edit1.text: = 'server stop'
End;
Procedure tform1.idtcpserver1execute (athread: tidpeerthread );
VaR
M_string: string;
Begin
M_string: = athread. Connection. readln ();
If m_string = 'begin' then
Begin
Athread. Connection. writeln ('I want to upload the text! ');
Edit1.text: = 'transfer preparation ';
Exit;
End;
If m_string = 'end' then
Begin
Edit1.text: = 'transfer termination ';
Exit;
End;
If m_string = 'qx' then
Begin
Edit1.text: = 'cancel transfer ';
Exit;
End;
End;
Procedure tform1.button2click (Sender: tobject );
Begin
Idtcpserver1.destroy;
Edit1.text: = 'server stop ';
End;
End.
Source code download: http://download.csdn.net/source/1261880
Delphi TCP/IP idtcpserver1 instance 1