Senin, 15 Juni 2015

Contoh Sederhana Code Delphi IdTcp Server Client 2015

Berikut ini adalah Contoh Sederhana Code Delphi IdTcp Server Client 2015 Yang mungkin ingin anda pelajari dan sebelumnya juga mimin sudah share seputar Contoh Dasar Source Code Tcp Connection Exception Client ok dan berikut dibawah ini adalah contoh listing programnnya dan untuk source code contoh jadinya silahkan ada dibawah diakhir postingan ini, silahkan disimak.

IdTcp Server Client 2015
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, ExtCtrls, IdBaseComponent, IdComponent,
  IdTCPServer, IdTCPConnection, IdTCPClient, IdAntiFreezeBase, IdAntiFreeze;

type
  TForm1 = class(TForm)
    IdTCPServer1: TIdTCPServer;
    Panel1: TPanel;
    StatusBar1: TStatusBar;
    ListBox1: TListBox;
    Memo1: TMemo;
    Button1: TButton;
    Button2: TButton;
    IdTCPClient1: TIdTCPClient;
    IdAntiFreeze1: TIdAntiFreeze;
    Timer1: TTimer;
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure IdTCPServer1Connect(AThread: TIdPeerThread);
    procedure IdTCPServer1Execute(AThread: TIdPeerThread);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Memo1KeyPress(Sender: TObject; var Key: Char);
    procedure IdTCPClient1Connected(Sender: TObject);
    procedure IdTCPClient1Disconnected(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
IdTCPServer1.DefaultPort:=80;
IdTCPServer1.Active:=true;
IdTCPClient1.Host:='127.0.0.1';
IdTCPClient1.Port:=8877;
IdAntiFreeze1.Active:=true;
IdAntiFreeze1.OnlyWhenIdle:=true;
IdAntiFreeze1.IdleTimeOut:=10;
end;

procedure TForm1.IdTCPServer1Connect(AThread: TIdPeerThread);
var
penuh:AnsiString;
begin
StatusBar1.Panels[0].Text:='Connected';
penuh:=AThread.Connection.Socket.Binding.PeerIP; //ip no
ListBox1.Items.Add(penuh);
AThread.Connection.WriteLn('capsa'); //cara apa saja
end;

procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
var
pesan:AnsiString;
begin
 pesan:=AThread.Connection.ReadLn();
 memo1.Lines.Add(pesan);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if IdTCPClient1.Connected then
 begin
 IdTCPClient1.Disconnect();
 Button1.Caption:='Disconnected';
 end
 else
 begin
 IdTCPClient1.Connect();
 button1.Caption:='Connected';
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
chat:AnsiString;
begin
chat:=Memo1.Lines.Strings[Memo1.Lines.count-1]; //Anda
IdTCPClient1.WriteLn('<contoh>'+chat); //Dia
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
chat:AnsiString;
begin
if IdTCPClient1.Connected then
 begin
 chat:=IdTCPClient1.ReadLn(); //saya
 memo1.Lines.Add(chat);
 end;

end;

procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
var
chat:AnsiString;
begin
if Key=#13 then
 begin
 chat:=memo1.Lines.Strings[Memo1.Lines.count-1]; //Anda
 IdTCPClient1.WriteLn('<contoh>'+chat); //Dia
 end;

end;

procedure TForm1.IdTCPClient1Connected(Sender: TObject);
begin
label1.Caption:='Server Connected';
end;

procedure TForm1.IdTCPClient1Disconnected(Sender: TObject);
begin
label1.Caption:='Server Disconnected';
end;

end.

Untuk Contoh source code jadinya bisa anda download secara gratis DISINI via situs tusfiles dan itu saja info seputar Contoh Sederhana Code Delphi IdTcp Server Client 2015 terima kasih dari mimin atas kesediaannya berkunjung kesini.

Post Selanjutnya; Source Code Delphi 7 Proxy Server With IdHTTP 2015