⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 点对点的通信程序
💻 PAS
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -