Client server application – Delphi tutorial

Delphi tutorial Client server application
http://xkobyx.blogspot.com/

This is Delphi Tutorial about client-server application, and as usual you can find here source code for this app, and also exe files at address : https://drive.google.com/open?id=0B_njK7HczCjDekg0WG1hamUyWTA

Source code for client app :
unit MainForm;

interface

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

type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
GroupBox1: TGroupBox;
CheckBox1: TCheckBox;
Label3: TLabel;
Label4: TLabel;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
ClientSocket1: TClientSocket;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure ClientSocket1Connect(Sender: TObject; Socket: TCustomWinSocket);
procedure ClientSocket1Disconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
ClientSocket1.Active:=False;
ClientSocket1.Host:=Edit1.Text;
ClientSocket1.Port:=StrToInt(Edit2.Text);
ClientSocket1.Active:=True;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
ClientSocket1.Socket.SendText(Edit5.Text);
Memo1.Lines.Add(‘Me : ‘+edit5.Text);
end;

procedure TForm1.ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
begin
CheckBox1.Checked:=Socket.Connected;
Edit3.Text:=Socket.LocalAddress;
Edit4.Text:=Socket.LocalHost;
Memo1.Lines.Clear;

end;

procedure TForm1.ClientSocket1Disconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
CheckBox1.Checked:=Socket.Connected;
end;

procedure TForm1.ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
begin
Memo1.Lines.Add(ClientSocket1.Socket.ReceiveText);
end;

end.
Source code for server app :
unit Main;

interface

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

type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
CheckBox1: TCheckBox;
Edit1: TEdit;
Button1: TButton;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
Label6: TLabel;
Button2: TButton;
Memo1: TMemo;
ServerSocket1: TServerSocket;
procedure Button1Click(Sender: TObject);
procedure ServerSocket1Accept(Sender: TObject; Socket: TCustomWinSocket);
procedure Button2Click(Sender: TObject);
procedure ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
port:Integer;
begin
ServerSocket1.Active:=False;
port:=StrToInt(Edit1.Text);
ServerSocket1.Port:=port;
ServerSocket1.Active:=True;
Edit4.Text:=’Listening…’;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
ServerSocket1.Socket.Connections[0].SendText(Edit6.Text);
Memo1.Lines.Add(‘Me : ‘+Edit6.Text);
Edit6.Text:=”;
end;

procedure TForm1.ServerSocket1Accept(Sender: TObject; Socket: TCustomWinSocket);
begin
CheckBox1.Checked:=true;
Edit2.Text:=Socket.RemoteAddress;
Edit3.Text:=Socket.RemoteHost;
Edit5.Text:=Socket.LocalAddress;
Edit4.Text:=’Connected’;
end;

procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
begin
Memo1.Lines.Add(Socket.RemoteHost+’ : ‘+Socket.ReceiveText);
end;

end.

Comments

Fabiano da Silva says:

Muito bom parabéns! onde posso baixar o Socket? poderia me indicar?

Ninaa Ninq says:

هل استطيع السؤال بالعربية ارجوكم

bob nacer says:

Can you please make a P2P (peer to peer) chat application in a local network, i really need it, and thx :)

Robo Ian says:

How did you connect the client to the server ?

Stanislav Hristakiev says:

This code have a problem with connection and Is no worked!
Error message to connect is socket error 10061
(In C++ simple apps on Help file RAD Studio “Creating the Web Interface (InterBase Tutorial) ” for Client apps have a wrong code – line – ClientDataSet1->RemoteServer = UserSession->DSProviderConnection1; In same tutorial for Delphi code have not problem! )

MESDOCS MESDOCCS says:

Good work bro ! I hope you keep teaching i am fan now.

i would be so happy if you make a tutorial about multiscreen capture of multiple screens of multipl servers i mean” thumbnails”

this what i am looking for http://rmklever.com/wp-content/uploads/ThumbsRating.jpg

inorder to help you i fond a pretty good compenent heer

http://rmklever.com/?tag=rkview

hope you post something heer form me good by

Lodewyk van der Westhuyzen says:

Hey, I like your work Mr.Whitehat. How can I do this on Delphi 7? xD

paraescucharrap says:

This is a TCP Client/Server application of course, right?

SA says:

i am vb coding i see the delphi so easy and fast

ziaddz says:

very nice work, but when I try it cont see the message who sent from server to client, only this problem,,can you explain me ?

Juan David JALLO COAQUIRA says:

Excelente aplicacion… sigan asi saludos.

Write a comment

*

Human Verification: In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.


Do you like our videos?
Do you want to see more like that?

Please click below to support us on Facebook!

Send this to a friend

▷ Other ReviewsVehicles▷ Show Cars▷ Motorbikes▷ Scooters▷ Bicycles▷ Rims & Tires▷ Luxury BoatsFashion▷ Sunglasses▷ Luxury Watches▷ Luxury Purses▷ Jeans Wear▷ High Heels▷ Kinis Swimwear▷ Perfumes▷ Jewellery▷ Cosmetics▷ Shaving Helpers▷ Fashion HatsFooding▷ Chef Club▷ Fooding Helpers▷ Coktails & LiquorsSports▷ Sport Shoes▷ Fitness & Detox▷ Golf Gear▷ Racquets▷ Hiking & Trek Gear▷ Diving Equipment▷ Ski Gear▷ Snowboards▷ Surf Boards▷ Rollers & SkatesEntertainment▷ DIY Guides▷ Zik Instruments▷ Published Books▷ Music Albums▷ Cine Movies▷ Trading Helpers▷ Make Money▷ Fishing Equipment▷ Paintball Supplies▷ Trading Card Games▷ Telescopes▷ Knives▷ VapesHigh Tech▷ Flat Screens▷ Tech Devices▷ Camera Lenses▷ Audio HiFi▷ Printers▷ USB Devices▷ PC Hardware▷ Network Gear▷ Cloud Servers▷ Software Helpers▷ Programmer Helpers▷ Mobile Apps▷ Hearing AidsHome▷ Home Furniture▷ Home Appliances▷ Tools Workshop▷ Beddings▷ Floor Layings▷ Barbecues▷ Aquarium Gear▷ Safe Boxes▷ Office Supplies▷ Security Locks▷ Cleaning ProductsKids▷ Baby Strollers▷ Child Car Seats▷ Remote ControlledTravel▷ Luggages & Bags▷ Airlines Seats▷ Hotel Rooms▷ Fun Trips▷ Cruise Ships▷ Mexico Tours