unit1.pas
来自「点对点的通信程序」· PAS 代码 · 共 62 行
PAS
62 行
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Sockets;
type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Label2: TLabel;
Button1: TButton;
Button2: TButton;
TcpClient1: TTcpClient;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses unit2;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
try
TcpClient1.RemoteHost := Trim(Edit1.Text); //获取IP地址
TcpClient1.RemotePort := Trim(Edit2.Text); //获取端口号
TcpClient1.Active:=False;
TcpClient1.Connect; //连接服务器
if TcpClient1.Connected then //连接成功
application.MessageBox('服务器连接成功。','明日科技')
else
application.MessageBox('服务器连接失败。','明日科技');
except
ShowMessage('服务器连接失败。');
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
TcpClient1.Close;
showmessage('客户端已断开');
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?