📄 server.pas
字号:
unit server;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPServer, StdCtrls;
type
TForm1 = class(TForm)
IdTCPServer1: TIdTCPServer;
Label1: TLabel;
Label2: TLabel;
procedure IdTCPServer1Execute(AThread: TIdPeerThread);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure IdTCPServer1Connected(AThread: TIdPeerThread);
private
{ Private declarations }
StringListZipCode: TStringList;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
StringListZipCode:=TStringList.Create;
StringListZipCode.LoadFromFile(ExtractFilePath(Application.EXEName) + 'ZipCodes.dat');
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
StringListZipCode.Free;
end;
procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
var
sClientCommand:string;
begin
with AThread.Connection do begin
sClientCommand := ReadLn;
//AnsiLowerCase(sClientCommand);//都变成小写
if SameText(sClientCommand, 'QUIT') then
begin
WriteLn('服务器停止服务,连接关闭!');
Disconnect;
end else if SameText(Copy(sClientCommand, 1, 8), 'ZipCode ') then
begin
WriteLn(StringListZipCode.Values[Copy(sClientCommand, 9, MaxInt)]);
end;
end;
end;
procedure TForm1.IdTCPServer1Connected(AThread: TIdPeerThread);
begin
AThread.Connection.WriteLn('与客户端连接成功');
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -