Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7289
  • Last Modified:

Simple idtcp Indy 10 example in Delphi 2009

Hi experts,

I´m trying to learn the idtcp indy components, i searched a little but all examples that i found i could´t run in my system, that is delphi 2009 with indy 10.

I want a simple example to transmit and read a simple string, no commands,no files, no nothing, i want just a start. The example must be like drop an edit and a idtcp then do this, then do that, step by step will be much apreciated.

Thank you very much.

0
arreegua
Asked:
arreegua
2 Solutions
 
arreeguaAuthor Commented:
"I want a simple example to transmit and read a simple string, no commands,no files, no nothing, i want just a start. The example must be like drop an edit and a idtcp then do this, then do that, step by step will be much apreciated."

Sorry i need a simple example, don´t want anything with ssl.
0
 
2266180Commented:
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
dprochownikCommented:
If you want to run samples you have found before I advice you an article about upgreading from Indy9 to 10: http://conferences.codegear.com/article/32160
In fact, in most cases there are only few simple steps to make this code working.

If you want direct sample, here you have one.
Create two Delphi projects, one for server and one for client.

SERVER:

On server main form put only TidTCPServer component and change its properties:
  • DefaultPort = 3080 (for example)
  • Active = true (Server will be active since application start)
For TidTCPServer handle event OnExecute as:

var
  vClientMessage: String;
begin
  try
    //Getting message from client
    vClientMessage := AContext.Connection.IOHandler.WaitFor(#13);

    //Logging
    self.Caption := vClientMessage; //Or do with that string whatever you want to

    //Sending response
    AContext.Connection.IOHandler.WriteLn('Server response');
 
  finally
    //Closing connection
    if AContext.Connection.Connected then
      AContext.Connection.Disconnect;
  end;

CLIENT:

On client main form put TidTCPClient and TBitBtn components.
For TidTCPClient component change properties
  • Port = 3080 (it have to be the same port as in server application)
  • Host = '127.0.0.1' (it is computer you want connect to. 127.0.0.1 is equal localhost, and means your own computer)
handle TBitBtn.OnClick event as:

  IdTCPClient1.Connect;
  try
    IdTCPClient1.IOHandler.WriteLn('Client message');
    Self.Caption := IdTCPClient1.IOHandler.ReadLn;
  finally
    IdTCPClient1.Disconnect;
  end;

Now when you run both of them, and click on Client App on the button, then Client will send to server message 'Client message'. Server will show it in its form caption, and response to client string 'Server response' which Client will show in its form caption.

I hope it's clear enough.


0
 
arreeguaAuthor Commented:
Thank you Very Much Ciuly and dprochownik.

The example that ciuly send me was exactly what i want but with a few errors to run with  delphi 2009 and indy 10(something with maxlines and lack of iohandler.writeLn) but it was ok, and i did the minor fixes to run following the dprochownik link to update from indy 9 to indy 10. Thank you very much Ciuly.

I ll Split points to reward the Ciuly efort but dprochownik answer was very complete, if i could i would give 500 point to every body.

Thank you very much both of you, when i grow up i want to be like u two , kakakak

cya guys thankyou again
0
 
arreeguaAuthor Commented:
Thankyou guys, exactly what i want
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now