Title: 3100 Developing TCPIPbased Server Applications using Indy Components
13100 - Developing TCP/IP-based Server
Applications using Indy Components
2What is Indy? (A Users Perspective)
- Indy is short for Internet Direct
- Project founded by Chad Z. Hower, aka Kudzu
- Originally called WinShoes
- Comes with Delphi or freely downloaded at
www.indyproject.org - This presentation focuses on Indy.Sockets Server
components
3Our company chose Indy because
- Actually I chose Indy based on usage with pet
projects dating back to when it was called
WinShoes - I originally liked these components because they
were FREE! - The company that I worked for basically did an
RFP among its developers based around a need for
networking ideas - Using Indy I was the only one who developed a
viable solution - Now on with the show
4Indy.Sockets Version 10
- Ships with Delphi 2005
- Contains 45 different server components
- Implements many standard protocols
5Using TidHTTPServer
- Does the world really need another WebServer?
- Thinking of rewriting Apache? Or IIS? Why
bother? - What about configuring software remotely?
- Network administrators could resolve server
issues from the comfort of their officeor home. - Or turn your desktop application into a browser
based application without having to master a
technology outside of Delphi? - You may still have to learn HTML or AJAX, but you
would not have to rely on IIS
6Example 1 TidHTTPServer
- This application will have an embedded web server
that allows for it to be configured remotely - Lets look at the code
7Using TidQOTDServer
- Heres another example of the many Servers Indy
provides - Quote Of The Day (QOTD) Provides a way for a
server program to provide a message to clients
8Example 2 - QOTDServerExample
- This application will run a QOTD server and allow
entering in any quote
- But wait! We also need a client application for
this.
9Example 2 The client application
- This is the application we will use to test the
server application - Now lets take a look at the code for both
applications
10TidTCPServer The mother of all TCP based servers
- The server components used in previous examples
are from the Indy.Sockets collection and are
derived from TidTCPServer - TidTCPServer is the counterpart to TidTCPClient
- Gives the developer the ability to implement
powerful TCP based applications - Enterprise level
- Peer-to-peer
- Implement standards that do not yet exist
11Before getting started
- Socket Blocking is the way Indy operates
- No other code executes during communication
- Every Server connection runs in its own thread
- This eliminates any obstacles blocking introduces
- Designed properly Indy servers scale very well
12Multi-Threaded Programming
- It is NOT evil
- Indy 10 helps Multi-Threaded beginners by
introducing support for fibers - Fibers are NOT threads
- They must be synchronized with a scheduler
- Multi-Threaded servers will run faster than Fiber
servers - By default, Indy uses threads
13Do you need to develop a server?
- Remember, servers do not initiate connections
- Clients initiate connections
- If you are developing the next great peer-to-peer
program you need both a server and a client
14What are ports?
- A port is a number that is used to identify
connections using your protocol - Be careful choosing a port number as it may be
used by another application - To get more information on port numbers go to the
Internet Assigned Numbers Authority or
www.iana.org
15One Last Question
- Will clients remain connected to the server?
- Under Windows, connections have a nasty habit of
going stale - Sometimes this fools Indy
- A Heartbeat mechanism can help to maintain
connections over long periods of time - Send routine messages every few seconds
- Immediately know when a connection goes down
16Command Handlers A Quick Overview
- Previous to Indy 10, TidTCPServer allowed for the
use of an OnExecute event OR using Command
Handlers - OnExecute Event that handles ALL client
communication - CommandHandlers Custom event handlers for
specific TCP messages - TidCmdTCPServer is now the component to descend
from for using Command Handlers - Set CommandHandlersEnabled to TRUE As of 2/1/05
This is no longer needed or allowed - At some point our new component can be placed on
the palette and dropped on a form, but we will
not be doing that today
17Designing Your Protocol
- The developer needs to decide on the necessary
commands - Cryptic or Verbose It is up to the developer
- The example that follows is a variation of the
original webserver example - Allows for remote configuration of software
- Uses a single command COLOR with different
parameters for setting our form color - To maintain connections with the client, it
implements a heartbeat mechanism
18High Speed Command Handling Using PostMessage
- Command Handlers are event handling objects that
run in their own connection thread - Every TidCommandHandler object has an OnCommand
event that needs to have a TryExcept surrounding
its code - PostMessage is used to get commands to the GUI
- This is a multi-threaded program, therefore
special care must be taken - Whenever the application writes to a client a
TThreadList is accessed
19Example 3 - TCPServerExample
20Example 3 The Client Application
- The main form
- Now lets see the code
21Congratulations!
- If everything worked out, you just ran the server
and the client much like the earlier HTTP Server
demonstration - Any questions?
22Conclusion
- This is only the beginning
- For Standard Protocols or custom protocols Indy
is a solid way to go - Indy is Free
- Source Code is included
- Newsgroup Support
- You can buy technical support
23Thank You
- Thank You so much for your time!