Home > Back-end >  Feel just a little bit, teachers teach.
Feel just a little bit, teachers teach.

Time:02-19

This is the code, download function is available, communication no problem,



I want to achieve the effect of is: the client access to the service side of each Edit content,

The server code
The unit Server_Indy;

Interface

USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent IdComponent, IdTCPServer ComCtrls, Buttons,
StdCtrls IdAntiFreezeBase, IdAntiFreeze IniFiles;
Type
TForm1=class (TForm)
GroupBox1: TGroupBox;
Label2: TLabel;
PortEdit: TEdit;
Startbtn: TButton;
Endbtn: TButton;
Label3: TLabel;
IdTCPServer1: TIdTCPServer;
IdAntiFreeze1: TIdAntiFreeze;
StatusBar1: TStatusBar;
Label1: TLabel;
Label4: TLabel;
Edit1: TEdit;
Edit2: TEdit;
GroupBox2: TGroupBox;
Memo1: TMemo;
Edit3: TEdit;
Label5: TLabel;
Edit4: TEdit;
Label6: TLabel;
Procedure FormCreate (Sender: TObject);
Procedure FormClose (Sender: TObject; Var Action: TCloseAction);
Procedure startbtnClick (Sender: TObject);
Procedure endbtnClick (Sender: TObject);
Procedure IdTCPServer1Connect (AThread: TIdPeerThread);
Procedure IdTCPServer1Execute (AThread: TIdPeerThread);
Procedure IdTCPServer1Disconnect (AThread: TIdPeerThread);
Procedure IdTCPServer1ListenException (AThread: TIdListenerThread;
AException: Exception);

Private
{Private declarations}
Public
Procedure AddChat;
{procedure DisPlayChat; }
end;

Var
Form1: TForm1;
ChatStr: string;
Implementation

{$R *. DFM}

Procedure TForm1. FormCreate (Sender: TObject);
Var
IniFile: TInifile;
The begin
IniFile:=TIniFile. Create (ExtractFilePath (Paramstr (0)) + 'Connect. Ini');
PortEdit. Text:=IniFile. ReadString (' Option ', 'Dbprot', '8198');
Edit3. Text:=IniFile. ReadString (' Option ', 'DbServer', 'computer');
Edit1. Text:=IniFile. ReadString (' Option ', 'DbName', 'database');
Edit2. Text:=IniFile. ReadString (' Option ', 'the DbA', 'SA');
Edit4. Text:=IniFile. ReadString (' Option ', 'DbPw', "password");
IdTcpServer1. Active:=False;
Startbtn. Enabled:=True;
Endbtn. Enabled:=False;
end;

Procedure TForm1. FormClose (Sender: TObject; Var Action: TCloseAction);
The begin
IdTcpServer1. Active:=False;
end;

Procedure TForm1. StartbtnClick (Sender: TObject);
The begin
With IdTcpServer1 do
The begin
Bindings. The Clear;
IP Bindings. Add. :='127.0.0.1;
Bindings. Add. Port:=StrToInt (portEdit. Text);
Active:=True;
Endbtn. Enabled:=True;
Startbtn. Enabled:=false;
Memo1. Lines. Text:='+ + + + + service is started! + + + + + + Ariel ';
end;

end;

Procedure TForm1. EndbtnClick (Sender: TObject);
The begin
IdTcpServer1. Active:=False;
Endbtn. Enabled:=False;
Startbtn. Enabled:=True;
Memo1. Lines. Text:='+ + + + + + + + + service has stopped! + + + + + + Ariel ';
end;

Procedure TForm1. IdTCPServer1Connect (AThread: TIdPeerThread);
The begin
Memo1. Lines. Text:='from the host' + AThread. Connection. The Socket. The Binding. The PeerIP + 'Connection request has been accepted;
AThread. Connection. WriteLn (' Ariel: welcome to connect to the server, wholeheartedly at your service ');
end;

Procedure TForm1. IdTCPServer1Execute (AThread: TIdPeerThread);
Var chat: string;
The begin
With AThread. Connection do
The begin
Chat:=ReadLn ();
ChatStr: chat=+ + AThread. 'from the host' Connection. Socket. Binding. PeerIP;
AThread. The Synchronize (AddChat);
{AThread. The Synchronize (DisPlayChat); }
end;
end;
Procedure TForm1. AddChat ();
The begin
Memo1. Lines. The Add (chatStr);
end;
{procedure TForm1. DisPlayChat ();
The begin
ChatReceived:=sendEdit. Text;
end; }
Procedure TForm1. IdTCPServer1Disconnect (AThread: TIdPeerThread);
The begin
Memo1. Lines. Text:='from the host' + AThread. Connection. The Socket. The Binding. The PeerIP + 'disconnected';
StatusBar1. Panels [0]. Text:='connection has been disconnected;
end;

Procedure TForm1. IdTCPServer1ListenException (AThread: TIdListenerThread;
AException: Exception);
The begin
StatusBar1. Panels [1]. The Text:='are connected... ';
end;

End.

///////////////////////////////////////////////////////////////////////////////////
The client code

The unit client_indy;

Interface

USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent IdComponent, IdTCPConnection IdTCPClient,
Buttons, StdCtrls;

Type
TForm1=class (TForm)
GroupBox1: TGroupBox;
Label1: TLabel;
IPEdit: TEdit;
Label2: TLabel;
PortEdit: TEdit;
Linkbtn: TButton;
Breakbtn: TButton;
Memo1: TMemo;
SendEdit: TEdit;
Sendbtn: TButton;
BitBtn1: TBitBtn;
IdTCPClient1: TIdTCPClient;
Procedure FormCreate (Sender: TObject);
Procedure linkbtnClick (Sender: TObject);
Procedure sendbtnClick (Sender: TObject);
Procedure breakbtnClick (Sender: TObject);
Private
{Private declarations}
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related