I already Increased it, and if it a lot of works, theres no worry to increased it again ;)
Main Topics
Browse All TopicsGreetings...
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.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
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
Hi, TheLeader, it isn't what I expect, but I'll help you.
he server code, it only answer to authenticated user. The user have to send the command "Password alsantos" to authenticate. If send any other command before authenticate, the server disconnect the user. You have to add 2 commandhandlers, On the idTcpServer1, click on CommandHandlers, and add 2 TIdCommandHandler with name Password and Time and Command "Password" and "Time" respectly. "The OnCommand" event of Password will call the procedure TForm1.IdTCPServer1Passwor
unit u_Server;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPServer, StdCtrls;
type
TForm1 = class(TForm)
IdTCPServer1: TIdTCPServer;
Button1: TButton;
Edit1: TEdit;
lbProcesses: TListBox;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure IdTCPServer1TimeCommand(AS
procedure IdTCPServer1NoCommandHandl
const AData: String; AThread: TIdPeerThread);
procedure IdTCPServer1Connect(AThrea
procedure FormCreate(Sender: TObject);
procedure IdTCPServer1PasswordComman
procedure IdTCPServer1Disconnect(ATh
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Authenticated: TStringList;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender
begin
try
IdTcpServer1.DefaultPort:=
IdTCPServer1.Active := true;
lbProcesses.Items.Append('
except on E : Exception do
lbProcesses.Items.Append('
end;
end;
procedure TForm1.Button2Click(Sender
begin
IdTCPServer1.Active := false;
lbProcesses.Items.Append('
end;
procedure TForm1.IdTCPServer1TimeCom
begin
if Authenticated.IndexOf(ASen
ASender.Thread.Connection.
else begin
ASender.Thread.Connection.
ASender.Thread.Connection.
end;
end;
procedure TForm1.IdTCPServer1NoComma
const AData: String; AThread: TIdPeerThread);
begin
if Authenticated.IndexOf(AThr
AThread.Connection.WriteLn
else begin
AThread.Connection.WriteLn
AThread.Connection.Disconn
end;
end;
procedure TForm1.IdTCPServer1Connect
begin
AThread.Connection.WriteLn
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Authenticated:=TStringList
end;
procedure TForm1.IdTCPServer1Passwor
begin
if ASender.Params.Strings[0] = 'alsantos' then
begin
Authenticated.Add(ASender.
ASender.Thread.Connection.
lbProcesses.Items.Add('Use
end
else begin
lbProcesses.Items.Add('Use
ASender.Thread.Connection.
ASender.Thread.Connection.
end;
end;
procedure TForm1.IdTCPServer1Disconn
begin
if Authenticated.IndexOf(AThr
Authenticated.Delete(Authe
lbProcesses.Items.Add('Use
end;
end.
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
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 ;)
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
hi i tried to start the server with button1, but nothing happend.
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
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
Business Accounts
Answer for Membership
by: alsantosPosted on 2003-10-26 at 20:08:48ID: 9624779
I think that it's a lot of work to a few points.
alsantos :)