D2 TEKNIK KOMPUTER (BSI PROGRAMMER)
Sharing Project Chat Client Server untuk kepentingan pemrograman delphi...
Tampilan Program :
Tampilan Program :
unit Chat;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ScktComp;
type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
Button2: TButton;
LV: TListView;
GroupBox2: TGroupBox;
Edit1: TEdit;
Memo1: TMemo;
Edit2: TEdit;
Button3: TButton;
SS: TServerSocket;
Button1: TButton;
procedure SSClientConnect(Sender: TObject; Socket: TCustomWinSocket);
procedure SSClientDisconnect(Sender: TObject; Socket: TCustomWinSocket);
procedure SSClientRead(Sender: TObject; Socket: TCustomWinSocket);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
SS.Active:=True;
Showmessage('Layanan Sudah Terbuka');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
SS.Active:=False;
Showmessage('Layanan Tidak Terbuka');
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
SS.Socket.Connections[LV.ItemIndex].SendText(Edit1.Text +' Pesan :' + Edit2.Text);
Memo1.lines.Add(Edit1.Text+' Pesan :'+Edit2.Text);
Edit2.Clear;
end;
procedure TForm1.SSClientConnect(Sender: TObject; Socket: TCustomWinSocket);
var L:Tlistitem;
begin
L:=LV.items.add;
L.caption:=Inttostr(Socket.handle);
L.Subitems.add(Socket.remotehost);
L.Subitems.add(socket.RemoteAddress);
L.Data:=Socket.Data;
end;
procedure TForm1.SSClientDisconnect(Sender: TObject; Socket: TCustomWinSocket);
var L:Tlistitem;
Begin
L:=LV.FindCaption(0,IntTostr(Socket.Handle),False,true,False);
If L <> NIL Then L.Delete;
end;
procedure TForm1.SSClientRead(Sender: TObject; Socket: TCustomWinSocket);
var Text:String;
Begin
Text:=Socket.ReceiveText;
Memo1.Lines.add(Text);
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ScktComp;
type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
Button2: TButton;
LV: TListView;
GroupBox2: TGroupBox;
Edit1: TEdit;
Memo1: TMemo;
Edit2: TEdit;
Button3: TButton;
SS: TServerSocket;
Button1: TButton;
procedure SSClientConnect(Sender: TObject; Socket: TCustomWinSocket);
procedure SSClientDisconnect(Sender: TObject; Socket: TCustomWinSocket);
procedure SSClientRead(Sender: TObject; Socket: TCustomWinSocket);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
SS.Active:=True;
Showmessage('Layanan Sudah Terbuka');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
SS.Active:=False;
Showmessage('Layanan Tidak Terbuka');
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
SS.Socket.Connections[LV.ItemIndex].SendText(Edit1.Text +' Pesan :' + Edit2.Text);
Memo1.lines.Add(Edit1.Text+' Pesan :'+Edit2.Text);
Edit2.Clear;
end;
procedure TForm1.SSClientConnect(Sender: TObject; Socket: TCustomWinSocket);
var L:Tlistitem;
begin
L:=LV.items.add;
L.caption:=Inttostr(Socket.handle);
L.Subitems.add(Socket.remotehost);
L.Subitems.add(socket.RemoteAddress);
L.Data:=Socket.Data;
end;
procedure TForm1.SSClientDisconnect(Sender: TObject; Socket: TCustomWinSocket);
var L:Tlistitem;
Begin
L:=LV.FindCaption(0,IntTostr(Socket.Handle),False,true,False);
If L <> NIL Then L.Delete;
end;
procedure TForm1.SSClientRead(Sender: TObject; Socket: TCustomWinSocket);
var Text:String;
Begin
Text:=Socket.ReceiveText;
Memo1.Lines.add(Text);
end;
end.
Berikut adalah Coding buat Chat Server :
unit Chat_Server;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ScktComp, dxGDIPlusClasses, ExtCtrls;
type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
Memo1: TMemo;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
CS: TClientSocket;
Edit3: TEdit;
Button2: TButton;
Image1: TImage;
procedure CSError(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
procedure CSRead(Sender: TObject; Socket: TCustomWinSocket);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
CS.Socket.SendText(Edit1.Text+' Pesan :'+ Edit2.Text);
Memo1.Lines.add(Edit1.Text+' Pesan :'+ Edit2.Text);
Edit2.Clear;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if Length(Edit3.Text)<=0 then
Begin
Application.MessageBox('Harus Terisi IP ADDRESS','Warning',MB_IconInformation);
Exit;
End;
if Button2.Caption = 'Connect' then
Begin
CS.Address:=Edit3.Text;
Cs.Active:=True;
Button2.Caption:= 'Disconnect';
End
Else if Button2.Caption = 'Disconnect' then
begin
CS.Address:=Edit3.Text;
Cs.Active:=False;
Button2.Caption:='Connect';
end;
end;
procedure TForm1.CSError(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
begin
ErrorCode:=0;
end;
procedure TForm1.CSRead(Sender: TObject; Socket: TCustomWinSocket);
Var Manual:String;
Begin
Manual:=Socket.ReceiveText;
Memo1.Lines.Add(Manual);
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ScktComp, dxGDIPlusClasses, ExtCtrls;
type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
Memo1: TMemo;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
CS: TClientSocket;
Edit3: TEdit;
Button2: TButton;
Image1: TImage;
procedure CSError(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
procedure CSRead(Sender: TObject; Socket: TCustomWinSocket);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
CS.Socket.SendText(Edit1.Text+' Pesan :'+ Edit2.Text);
Memo1.Lines.add(Edit1.Text+' Pesan :'+ Edit2.Text);
Edit2.Clear;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if Length(Edit3.Text)<=0 then
Begin
Application.MessageBox('Harus Terisi IP ADDRESS','Warning',MB_IconInformation);
Exit;
End;
if Button2.Caption = 'Connect' then
Begin
CS.Address:=Edit3.Text;
Cs.Active:=True;
Button2.Caption:= 'Disconnect';
End
Else if Button2.Caption = 'Disconnect' then
begin
CS.Address:=Edit3.Text;
Cs.Active:=False;
Button2.Caption:='Connect';
end;
end;
procedure TForm1.CSError(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
begin
ErrorCode:=0;
end;
procedure TForm1.CSRead(Sender: TObject; Socket: TCustomWinSocket);
Var Manual:String;
Begin
Manual:=Socket.ReceiveText;
Memo1.Lines.Add(Manual);
end;
end.
Silahkan Download Project Chat BSI ||Chat BSI||
Cara menggunakannya cukup simple saja , buka form chat client terlebih dahulu click konek baru kemudian buka form server lalu isi IP ADDRESS Komputer (Server) kemudian Click Konek...
Untuk Chatting : tinggal isi nama dan pesan sesuai dengan form yang ada..
NB : Untuk form client (Click di string grid terlebih dahulu apabila sudah muncul host server x agar bisa melakukan chatting)...
Cara menggunakannya cukup simple saja , buka form chat client terlebih dahulu click konek baru kemudian buka form server lalu isi IP ADDRESS Komputer (Server) kemudian Click Konek...
Untuk Chatting : tinggal isi nama dan pesan sesuai dengan form yang ada..
NB : Untuk form client (Click di string grid terlebih dahulu apabila sudah muncul host server x agar bisa melakukan chatting)...