Link to home
Start Free TrialLog in
Avatar of sheepfarmer
sheepfarmer

asked on

TCP Socket server handling multiple requests

Morning,

I have a basic socket server up and running - it listens on port x, when it receives an external request it does some stuff with that connection, then it resets to handle the next request.

I want to make the socket server so that it can handle multiple requests at the same sometime.

Could I get some guidance on what techniques will be required for this.  In my mind, the following would seem relevent:
1. Creating a new tread for each incoming connection
2. Somehow passing off each new connection to another port (random) so that port x is freed up to await the next connection
3. Ensuring that the working code that does stuff with the external request is thread safe.

Is there anything else I should consider.

Thanks
SF
ASKER CERTIFIED SOLUTION
Avatar of MerijnB
MerijnB
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sheepfarmer
sheepfarmer

ASKER

What is the primary difference between blocking and non-blocking?

The application is relatively straightforward:
1. It listens on a port
2. On connection, it talks to the client doing some 'stuff' for a period of time (could be up to 30 mins)
3. In the meantime, it needs to listen and handle other incoming connections
4. The 'stuff' it does in the background is threadsafe (i.e. no conflict).

Currently just using the build in TSocketServer component in non-blocking mode.  
Are there better componenets for this sort of thing?  Delphi 2009 BTW.

Thanks
SF

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The ICS looks good, in particular its support for SSL - have you any experience with SSL in that library - I assume that if both ends of the link (client and server) use Delphi and ICS, a secure connection could be established.

On the blocking side of things, could you set a timeout so that if no response is received, you get back control of the thread?


SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
On the blocking issue, I have another project where an application talks to an external device via TCP.  The communication is such that the application makes a request, then waits for a response.  This would appear more like the blocking model since if no response is received, this is an error.

With the non-blocking model, you would have to put in an external 'timer' or some such to generate a timeout if no response is received in a specified period of time.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
> I do have some ICS ones, but you might find the indy ones easier to understand.

Always nice to see different opinions through different approaches, I feel the other way around :)
I would like to see the ICS ones too if available.

Thanks
SF
> Always nice to see different opinions through different approaches, I feel the other way around :
My personal preference is for ICS or native TSocketServer ;-)

Ok, before this gets into an opinion war, I'll close the question - thanks for your help all.

SF