Delphi Code (Simple Chatt – Server)

2 05 2009

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ScktComp, StdCtrls;

type
TForm1 = class(TForm)
Memo1: TMemo;
Memo2: TMemo;
Button1: TButton;
Button2: TButton;
Button3: TButton;
ServerSocket1: TServerSocket;
procedure FormCreate(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure ServerSocket1Accept(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
memo1.Clear;
memo2.Clear;
serversocket1.Port:=1880;
serversocket1.Open;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
application.Terminate;
end;

procedure TForm1.ServerSocket1Accept(Sender: TObject;
Socket: TCustomWinSocket);
begin
memo1.Lines.Add('Connected to: '+socket.RemoteHost);
end;

procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
begin
memo1.Lines.Add(socket.ReceiveText);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
serversocket1.Active:=false;
memo1.Clear;
memo1.Lines.Add('koneksi terputus');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
memo1.Lines.Add('server: '+memo2.Text);
if(serversocket1.Socket.activeconnections>0)then
serversocket1.Socket.Connections[0].SendText('server: ' +memo2.text);
end;

end.

Actions

Information

2 responses

12 03 2010
25 05 2013
Ryan LX (@linuxmint26)

thanks gan source nya😀

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: