Home arrow Delphi-Kylix arrow Page 4 - Using the Command Handler Method in Delphi
DELPHI-KYLIX

Using the Command Handler Method in Delphi


In the previous article, we discussed the various ways in which we can create indy servers. Picking up from where we left off, in this article we are going to build a server application using the CommandHandler method.

Author Info:
By: Leidago
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
December 18, 2006
TABLE OF CONTENTS:
  1. · Using the Command Handler Method in Delphi
  2. · Implementing the Second and Third Commands
  3. · Setting the Greeting
  4. · Indy clients
  5. · Building a More Appealing Client

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Using the Command Handler Method in Delphi - Indy clients
(Page 4 of 5 )

Clients are very simple to implement, because they basically just send a request and process the response. Dropping an idTCPClient component on a form with a button, an edit box and a memo is basically all it takes to create a client. Once you connect the client to a server, all you do then is send a command and wait for a response from the server, which you display in the memo.

From our previous article we know that clients need a hostname or IP address and port number to connect to a server. So connecting to a client takes the form:

with IndyClient do begin

Host := 'myhostname.com' ; // You can use an IP Address here as well.

Port := 6000; //This is where the server is listening

Connect;

Try

// Read and write data here

finally

Disconnect;

end;

end;

The code above shows the minimum requirements for creating a client application:

  • Set host property.
  •  Set port property.
  •  Connect.
  •  Reading/Writing.
  •  Disconnect.

We also need to consider exception handling. In most cases when using client-server applications, the server application will be located at a remote place. Since you don't know if the server is running or not, you should make provisions in your code for any exceptions that may result from the server being inactive. All indy exceptions are descended from EIdException:

try

IdTCPClient1

 try

// read/write here

finally IdTCPClient1

except

on E: EIdException do begin

ShowMessage('Indy Exception: ' + E.Message);

end else begin

ShowMessage('VCL Exception: ' + E.Message);

end;

end;


blog comments powered by Disqus
DELPHI-KYLIX ARTICLES

- Loading an XML Document into the DOM
- Delphi Wrapper Classes and XML
- Delphi and the DOM
- Delphi and XML
- Internet Access: Client Service
- Finishing the Client for an Internet Access ...
- The Client for an Internet Access Control Ap...
- User Management for an Internet Access Contr...
- Important Procedures for an Internet Access ...
- Server Code for an Internet Access Control A...
- Constructing the Interface for an Internet A...
- Building a Server Application for an Interne...
- Building an Internet Access Control Applicat...
- Client Dataset: Working with Data Packets an...
- Using the Client Dataset in an N-Tiered Appl...

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 6 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials