TheLeader
asked on
Indy TCP (Client/Server)
Greetings...
I Need a very Clear example of how to send & receive(commands and string)using indy TCP Client, Server Client ?
also the Server has a password to establish the connection from the client.
thank you for your time.
I Need a very Clear example of how to send & receive(commands and string)using indy TCP Client, Server Client ?
also the Server has a password to establish the connection from the client.
thank you for your time.
ASKER
I already Increased it, and if it a lot of works, theres no worry to increased it again ;)
For the server:
- put TIdTCPServer component on your form
- adjust the port setting on the property inspector.
- for auto activation, set the property Active to True on the property inspector.
- Indy TCP server works in command/response mechanism, to add a command in your protocol,
click on property CommandHandlers property on your property inspector then add your commands there.
- On each Command you can define the command string and use the OnCommand event to define
your own actions.
- You can also use response (numericcode, text, etc) to standardize your responses.
Run your test server and test it first with a telnet application connecting to the defined ports.
For the client:
- Try the ReadLn and WriteLn methods from the TIdTCPClient component to read/write strings
from/to the server.
An example code is more difficult to be read... this explanation will help more, I think.
regards,
huferry
- put TIdTCPServer component on your form
- adjust the port setting on the property inspector.
- for auto activation, set the property Active to True on the property inspector.
- Indy TCP server works in command/response mechanism, to add a command in your protocol,
click on property CommandHandlers property on your property inspector then add your commands there.
- On each Command you can define the command string and use the OnCommand event to define
your own actions.
- You can also use response (numericcode, text, etc) to standardize your responses.
Run your test server and test it first with a telnet application connecting to the defined ports.
For the client:
- Try the ReadLn and WriteLn methods from the TIdTCPClient component to read/write strings
from/to the server.
An example code is more difficult to be read... this explanation will help more, I think.
regards,
huferry
how about checking the examples ?
basic Chat should be enough
basic Chat should be enough
ASKER
ok I will try it "huferry"
but what about the server password ?
"Lee_Nover"
chat example(string) will be good but what about the commands & the server password !
but what about the server password ?
"Lee_Nover"
chat example(string) will be good but what about the commands & the server password !
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
now, the client side, it's more simple to understand.
unit u_Client;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient;
type
TForm1 = class(TForm)
IdTCPClient1: TIdTCPClient;
Button1: TButton;
Button2: TButton;
lbCommunication: TListBox;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Button3: TButton;
Button4: TButton;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure IdTCPClient1Disconnected(S ender: TObject);
procedure IdTCPClient1Connected(Send er: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button2Click(Sender : TObject);
begin
if IdTCPClient1.Connected then
try
IdTCPClient1.Disconnect;
except on E : Exception do
ShowMessage(E.Message);
end;
end;
procedure TForm1.Button1Click(Sender : TObject);
begin
lbCommunication.Items.Clea r;
with IdTCPClient1 do
begin
Host := Edit1.Text;
Port := StrToint(Edit2.Text);
try
Connect;
lbCommunication.Items.Add( idTCPClien t1.ReadLn) ;
except on E : Exception do
ShowMessage(E.Message);
end;
end;
end;
procedure TForm1.Button3Click(Sender : TObject);
var
LCommand, LInString : String;
begin
LCommand := Edit3.Text;
with IdTCPClient1 do
begin
try
WriteLn(LCommand);
LInString := ReadLn;
lbCommunication.Items.Inse rt(0,'We Send -> ' + LCommand);
lbCommunication.Items.Inse rt(0,'Serv er Send -> ' + LInString);
except
on E : Exception do
ShowMessage(E.Message);
end;
end;
end;
procedure TForm1.IdTCPClient1Disconn ected(Send er: TObject);
begin
lbCommunication.Items.Inse rt(0,'Disc onnected from remote server');
end;
procedure TForm1.IdTCPClient1Connect ed(Sender: TObject);
var
LString : String;
begin
LString := IdTCPClient1.ReadLn;
lbCommunication.Items.Inse rt(0,'Conn ected to remote server');
lbCommunication.Items.Inse rt(0,'Serv er send -> ' + LString);
end;
procedure TForm1.Button4Click(Sender : TObject);
begin
with IdTCPClient1 do
begin
try
WriteLn('Password alsantos');
lbCommunication.Items.Inse rt(0,'We send the password alsantos');
lbCommunication.Items.Inse rt(0,'Serv er send -> ' + ReadLn);
except
on E : Exception do
ShowMessage(E.Message);
end;
end;
end;
end.
alsantos ;)
unit u_Client;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient;
type
TForm1 = class(TForm)
IdTCPClient1: TIdTCPClient;
Button1: TButton;
Button2: TButton;
lbCommunication: TListBox;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Button3: TButton;
Button4: TButton;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure IdTCPClient1Disconnected(S
procedure IdTCPClient1Connected(Send
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button2Click(Sender
begin
if IdTCPClient1.Connected then
try
IdTCPClient1.Disconnect;
except on E : Exception do
ShowMessage(E.Message);
end;
end;
procedure TForm1.Button1Click(Sender
begin
lbCommunication.Items.Clea
with IdTCPClient1 do
begin
Host := Edit1.Text;
Port := StrToint(Edit2.Text);
try
Connect;
lbCommunication.Items.Add(
except on E : Exception do
ShowMessage(E.Message);
end;
end;
end;
procedure TForm1.Button3Click(Sender
var
LCommand, LInString : String;
begin
LCommand := Edit3.Text;
with IdTCPClient1 do
begin
try
WriteLn(LCommand);
LInString := ReadLn;
lbCommunication.Items.Inse
lbCommunication.Items.Inse
except
on E : Exception do
ShowMessage(E.Message);
end;
end;
end;
procedure TForm1.IdTCPClient1Disconn
begin
lbCommunication.Items.Inse
end;
procedure TForm1.IdTCPClient1Connect
var
LString : String;
begin
LString := IdTCPClient1.ReadLn;
lbCommunication.Items.Inse
lbCommunication.Items.Inse
end;
procedure TForm1.Button4Click(Sender
begin
with IdTCPClient1 do
begin
try
WriteLn('Password alsantos');
lbCommunication.Items.Inse
lbCommunication.Items.Inse
except
on E : Exception do
ShowMessage(E.Message);
end;
end;
end;
end.
alsantos ;)
If you want, I can send the source code for your email.
alsantos
alsantos
ASKER
yes I would like to
mido@ksaguys.com
mido@ksaguys.com
ASKER
"Alsantos" your code is perfect thank you :)
but could you explain what do you mean by
except on E : Exception do
when it will do the except ?
but could you explain what do you mean by
except on E : Exception do
when it will do the except ?
Thanks TheLeader...
I use try/except to protect the code. So, I use:
Try
.... // it will try the code here, but it can generate an error, for example
// the IdTCPClient1 isn't connected to a server.
// so it will generate an error and the Except will catch this error
// and show a message on the screen with the cause of this error
{ here the code that can generate an exception(error) }
Except
On E: Exception do
showmessage(E.Message); { here catch the error an show the error message }
alsantos
I use try/except to protect the code. So, I use:
Try
.... // it will try the code here, but it can generate an error, for example
// the IdTCPClient1 isn't connected to a server.
// so it will generate an error and the Except will catch this error
// and show a message on the screen with the cause of this error
{ here the code that can generate an exception(error) }
Except
On E: Exception do
showmessage(E.Message); { here catch the error an show the error message }
alsantos
I wrote this comment at friend's house. But it's me.
alsantos :)
alsantos :)
TheLeader, and if the code dont't generate an error, it just ignore the on E: Exception do ....
alsantos
alsantos
ASKER
Well, Thank "alsantos"
you really deserve A :)
here you go...
you really deserve A :)
here you go...
Thanks TheLeader :)
alsantos
alsantos
Hi, I've just tried your code above but it just locks up. Would it be possible to send me the code also, as this is a perfect example of a simple client-server I want to study.
Thanks... naru@eclipticdreams.com
Thanks... naru@eclipticdreams.com
hi i tried to start the server with button1, but nothing happend.
procedure TForm1.Button1Click(Sender : TObject);
begin
try
IdTcpServer1.DefaultPort:= StrToInt(E dit1.Text) ;
IdTCPServer1.Active := true;
ListBox1.Items.Append('Ser ver started')
except on E : Exception do
ListBox1.Items.Append('Ser ver not started');
end;
end;
could u also send me the source code..? nhatiboy@hotmail.com
thanx in advance
procedure TForm1.Button1Click(Sender
begin
try
IdTcpServer1.DefaultPort:=
IdTCPServer1.Active := true;
ListBox1.Items.Append('Ser
except on E : Exception do
ListBox1.Items.Append('Ser
end;
end;
could u also send me the source code..? nhatiboy@hotmail.com
thanx in advance
masterchow you can use IdTcpServer1.Bindings property in design mode to simply set the HostIP and Port like: 127.0.0.1:80
alsantos cannot help you anymore, the community moderators close their account.
my app use ado to handle database, and i try to use seek method, but it says "provider doesn't support this method" (index and seek method). can master help me to solve my BIG problem ...
^(~,~)^
^(~,~)^
I have to write a network management program in Delphi for monitoring switches and discovering when a switch fails. It should retrieve the status of the monitored device from its MIB file.
Could you provide me with any tips on how to design this. I have never programmed in Delphi before and am a complete newbie. But I understand all about network management.
The information will be sent to a Server every X seconds and any changes should be sent to the monitored devices, such as traps. I would be very grateful.
Thanks
Eilis
Could you provide me with any tips on how to design this. I have never programmed in Delphi before and am a complete newbie. But I understand all about network management.
The information will be sent to a Server every X seconds and any changes should be sent to the monitored devices, such as traps. I would be very grateful.
Thanks
Eilis
Dear TheLeader,
Can you send me the source code from alsantos about indy client server, caused of alsantos account has been closed. My email japriku2000@yahoo.com
Thanks
Can you send me the source code from alsantos about indy client server, caused of alsantos account has been closed. My email japriku2000@yahoo.com
Thanks
Dear TheLeader
Can u send me a compiled program to email : drago666@abv.bg
Thanks
Can u send me a compiled program to email : drago666@abv.bg
Thanks
Dear TheLeader,
Could you send me the source code to email: dunglq78@gmail.com
thanks alot
Could you send me the source code to email: dunglq78@gmail.com
thanks alot
alsantos :)