server.pas

来自「interpress 编程示例,SERVER&CLIENT」· PAS 代码 · 共 72 行

PAS
72
字号
unit server;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPServer;

type
  TForm1 = class(TForm)
    IdTCPServer1: TIdTCPServer;
    Label1: TLabel;
    procedure IdTCPServer1Execute(AThread: TIdPeerThread);
    procedure IdTCPServer1Connect(AThread: TIdPeerThread);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
  stringListZipcode:tstringlist;

    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
 var
  sc:string;
begin
   with athread.Connection do
   begin
     sc:=readln;
     if sametext(sc,'QUIT') then
     begin
       WriteLn('服务器停止服务,连接关闭!');
       disconnect;
     end ;

     if sametext(sc,'Zipcode') then
     begin
      WriteLn('server get====> Zipcode');
//      writeln(stringlistzipcode.Values[copy(sc,9,maxint)]);
      WriteLn(StringListZipCode.Values[Copy(sc, 9, MaxInt)]);
     end;
   end;
   
end;

procedure TForm1.IdTCPServer1Connect(AThread: TIdPeerThread);
begin
  AThread.Connection.WriteLn('与客户端连接成功');
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  stringlistzipcode:=tstringlist.Create ;
    stringlistzipcode.LoadFromFile('d:\zipcodes.dat');
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
   stringlistzipcode.Free ;
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?