Hi !

I feel a little dumb, as I am trying to understand something which seems evident to everyone, and so that I cannot find a clear answer. I hope you guys could enlight my questions:

I am trying to figure out how can a server handle multiple entrant connections. For instance, how work a Database Server to accept parallel requests and answer them, with sometimes big data, while only 1 port is available for this.

I imagine my 'SELECT' request arriving to the port 1234 of my DB server. This would lock the port 1234 to my connection, until (I guess) the server has something to answer. Once it has answered, the port would be once again free to serve a new request.
If so, I cannot understand how the service can be done, if I am dumping tables for 1 hour... this doesn't block the other connection !?!

What about a Game Server, for instance. You start a game, I connect to the server 1234, maybe temporarly, time to give indication of the game and exit. How can the server serve multiple connections on only 1 port !?!!

It sounds impossible, and I really feel I am missing something very big.. Please be not to hard with me :)))


Recommended Answers

You forgot to do your basic search. This question has a lot of good prior answers at:

Jump to Post

All 2 Replies

You can use select() with multiple file descriptors. You should also set a timeout value which is one of the arguments to select(). You need to more reading on this. It is very basic TCP/IP programming.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.