Title: How to handle pending connections to a server that is designed to handle a limited number of connections at a time
Tags: network-programming;client-server
Question: I wonder what is the best approach to handle the following scenario:
I have a server that is designed to handle only 10 connections at a time, during which the server is busy with interacting with the clients. However, while the the server is busy, there may be new clients who want to connect (as part of the next 10 connections that the server is going to accept). The server should only accept the new connections after it finishes with all previous 10 agents.
Now, I would like to have an automatic way for the pending clients to wait and connect to the server once it becomes available (i.e. finished with the previous 10 clients).
So far, I can think of two approaches: 1. have a file watch on the client side, so that the client will watch for a file written by the server. When the server finishes with 10 clients, it will write the file, and the pending clients will know it's time to connect; 2. make the pending clients try to connect the server every 5 - 10 secs or so until success, and the server will return a message indicating whether it is ready.
Any other suggestion would be much welcome. Thanks.

Here is the accepted answer: Of the two options you provide, I am inclined toward the 2nd option of "Pinging" the server. I think it is more complicated to have the server write a file to the client triggering another attempt.
I would think that you should be able to have the client waiting and simply send a READY signal. Keep a running Queue of connection requests (from Socket.Connection.EndPoint, I believe). When one socket completes, accept the next Socket off the queue.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2011:00:05/28/11', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<network-programming><client-server>', 'Title': 'How to handle pending connections to a server that is designed to handle a limited number of connections at a time', 'ViewCount': 175, 'id': 6161770, 'user_AboutMe': '', 'user_AccountId': 262976.0, 'user_DisplayName': 'skyork', 'user_Reputation': 6851.0, 'user_Views': 303.0, 'user_id': 548240.0}}