I wanna build a TCP/IP server that will be used by up to 100 concurrent clients, but still not sure how to get started.
at least I need the server to this:
Could anyone help how to get start with that,I looked at indy sample but they didn't help, also looked for most components but still searching.
Multithreading (Contd.) ∎ Multithreading allows a program to perform. multiple tasks concurrently. □ Although threads give the appearance of running. concurrently, in a single- processor system the interpreter is switching between the threads and running them one at a time.
The server can receive any number of connections on its single listening port, as long as a different address/port combination is used by each client.
A multithreaded server is any server that has more than one thread. Because a transport requires its own thread, multithreaded servers also have multiple transports. The number of thread-transport pairs that a server contains defines the number of requests that the server can handle in parallel.
Multithreaded Server: A server having more than one thread is known as Multithreaded Server. When a client sends the request, a thread is generated through which a user can communicate with the server. We need to generate multiple threads to accept multiple requests from multiple clients at the same time.
You need to use the TidTCPServer
which is multithreaded inside. No need for you to manage the threads. Everything is transparent, so in the way in which you write the application for one client, in (almost) the same way you will write it for many. See the OnConnect
event. There is a TidContext
parameter which has a TThreadList inside. You can use that event to 'register'/add your clients to your custom array/list and OnDisconnect
to remove the clients.
The OnExecute
event is triggered when the server receives a message. Use its parameters to read the message which is sent.
Also, you need another application which will be your client, using TidTCPClient
. In this application you will set the address of your server (see the Host property) as well as the Port which should match with the server's one. You should call Connect
(when the server is running) and to send strings you have SendCmd
method. (Also see IOHandler.WriteLn
if you want)
There are also other things but I think that's enough to get you started. Also you can post in Embarcadero's forums in the .Delphi.Winsock forum where the Indy team members are floating over. Or perhaps you can ask directly in .Delphi.Non-Technical and the guys there will guide you.
Another approach is DataSnap which is a more object-oriented layer over Indy (not to be confused with DBX) which gives your JSON, REST and other goodies. See for a small review here.
And another Delphi library option would be synapse which provides a simple framework that can easily be extended. There is an IOCPPool demo available in the contributed files which may be of assistance.
Synapse is more of a framework of classes than a component library. There is a vibrant and active user community that is ready to support any challenges. I use this library in Delphi 2010 without any problems (although I use the latest development version from SVN).
Being as they are not components, it is very easy to use the classes in simple console applications or windows services.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With