Using the Command Handler Method in Delphi - Setting the Greeting
(Page 3 of 5 )
Now we need to set the greeting text that will be displayed when a client first connects. This is entirely optional; your application will function perfectly fine with or without it. Click on the idCMDTCPServer1 component and go to its greeting property. Click on the plus sign and go to the "Text" option. Enter "Welcome to my Server" and click OK. Also, add "idcommandhandlers" to the form's uses clause.
Double click on the form's on create event and add the following code:
procedure TForm1.FormCreate(Sender: TObject);
begin
idcmdtcpserver1.DefaultPort:=6000;
idcmdtcpserver1.Active:=true;
end;
This procedure sets the port at which the server will listen for connections from clients and activates the server. The port number is completely random; you can set any non-known number here. We've covered port numbers in the previous article, so check to see which numbers you should and should not use.
Compile and run your project. While the application is running, go to your DOS prompt and start telnet by typing "telnet." You should now see the telnet prompt. Type "open localhost 6000".

I use "Localhost" because I'm running the server application on my local machine. If you are on a network, use your network IP address instead. I use the 6000 number because that's where we set the server to listen for connections. Press return and you should see something like this:

I've asked for a quote by typing "Aquote" and pressing the return key. In next screen I ask for today's date and I get:

Next I close down my connection:

It is very easy to implement your own protocol with indy servers, once you understand how indy works. CommandHandlers makes this process even easier because of their flexibility and properties, most of which we have not covered here. Hopefully this introduction will inspire you to start experimenting with this technology.
Next: Indy clients >>
More Delphi-Kylix Articles
More By Leidago