• delphi tcp/ip IdTCPServer1实例一


    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('我是要传的文字!');
           edit1.Text:='准备传输';
           exit;
           end;
      if m_string='end' then
      begin
           edit1.Text:='传输结束';
           exit;
           end;
      if m_string='qx' then
      begin
            edit1.Text:='取消传输';
            exit;
            end;
    end;


    procedure TForm1.Button2Click(Sender: TObject);
    begin
       IdTCPServer1.Destroy;

       edit1.Text:='Server stop';
    end;

    end.

    源代码下载:http://download.csdn.net/source/1261880

  • 相关阅读:
    idea添加类注释和方法注释
    蓝桥杯ALGO-1,区间k大数查询
    personalblog
    ul+li水平居中的几种方法
    前端ps部分
    帝国cms-tab
    帝国cms判断某一字段是否为空
    帝国cms建站总结-(分页)
    Js获取验证码倒计时
    前端截取字符串:JS截取字符串之substring、substr和slice详解
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/4007009.html
Copyright © 2020-2023  润新知