Solved

Simple idtcp Indy 10 example in Delphi 2009

Posted on 2008-10-27
6
7,082 Views
Last Modified: 2013-11-23
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
Comment
Question by:arreegua
6 Comments
 
LVL 5

Expert Comment

by:wd123
ID: 22812855
0
 
LVL 2

Author Comment

by:arreegua
ID: 22813110
"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
 
LVL 28

Assisted Solution

by:2266180
2266180 earned 100 total points
ID: 22816007
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

 
LVL 4

Accepted Solution

by:
dprochownik earned 400 total points
ID: 22817160
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
 
LVL 2

Author Comment

by:arreegua
ID: 22824339
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
 
LVL 2

Author Closing Comment

by:arreegua
ID: 31510298
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question