Hi,
I have a program which needs to connect multiple servers at the same time. The program has to collect data from each of servers and then make a decision regarding to the data received.
There are several requirements.
- Server (s) may shutdown anytime without any ack (e.g.power off).
- Client has to connect several servers.
- Every decision should "discuss" with servers; if one of them failed, the decision will based on others which still alive.
- The discussion should be fast, more than 200ms is not acceptable.
My design principle is like that:
- Create threads which every one connect to a server.
- Creating a sending queue on each thread.
- If the queue doesn't empty, then connect the server and send the data from queue to server.
- Wait message from server.
- Close the connection
There are also problems in the design.
- If I sent the message to server, how about if the server dead and no response? (receive timeout?)
- If we create and initiating socket in a short time, a lot of TIME_WAIT since the client will close the socket when send and receive operation finished.
- Since I have to connect multiple servers, if one of them are failed. I have to reconnect them, may say every 1 second a try?
Would you please give me some ideas that how to handle such kind of application? Thanks a lot!