Download presentation
Presentation is loading. Please wait.
Published byAustin Nelson Modified over 8 years ago
1
3100 - Developing TCP/IP-based Server Applications using Indy Components Christian Wilkerson
2
What is Indy? (A User’s 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 www.indyproject.org This presentation focuses on Indy.Sockets Server components
3
Our 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…
4
Indy.Sockets Version 10 Ships with Delphi 2005 Contains 45 different server components Implements many standard protocols
5
Using 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 office…or 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
6
Example 1 – TidHTTPServer This application will have an embedded web server that allows for it to be configured remotely Let’s look at the code…
7
Using TidQOTDServer Here’s 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
8
Example 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.
9
Example 2 – The client application This is the application we will use to test the server application Now let’s take a look at the code for both applications…
10
TidTCPServer – 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
11
Before 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
12
Multi-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
13
Do 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
14
What 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.orgwww.iana.org
15
One 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
16
Command 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
17
Designing 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
18
High 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 Try…Except 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
19
Example 3 - TCPServerExample The main form…
20
Example 3 – The Client Application The main form… Now let’s see the code…
21
Congratulations! If everything worked out, you just ran the server and the client much like the earlier HTTP Server demonstration Any questions?
22
Conclusion 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
23
Thank You Thank You so much for your time!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.