delphi tcp/ip IdTCPClient1实例一
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient;
type
TForm1 = class(TForm)
IdTCPClient1: TIdTCPClient;
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
IdTCPClient1.Host:='192.168.1.126';
IdTCPClient1.Port:=168;
IdTCPClient1.Connect();
if edit1.Text='begin' then
begin
IdTCPClient1.WriteLn('begin');
showmessage(IdTCPClient1.ReadLn());
end;
if edit1.Text='end' then
IdTCPClient1.WriteLn('end');
if edit1.Text='qx' then
IdTCPClient1.WriteLn('qx');
IdTCPClient1.Disconnect;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
IdTCPClient1.Disconnect;
end;
end.