views:

176

answers:

2

Context: Master server (Java, TCP) monitoring a list of hosted games (a different machine for the master server and for each hosted game server). Any user can host a game on his PC. Hosted games can last weeks or months.

Need: Knowing when hosted game servers are closed or no longer reachable.

Restriction 1: Can't rely on hosted servers' "gone offline update message", since those messages may never arrive (power down, Internet link cut, etc.)

Restriction 2: I'm not sure about TCP's built-in keep-alive, since it would mean a 24/7 open socket with each hosted server (correct me if I'm wrong)

Any thoughts?

+1  A: 

It sounds like you're running into what's known as the "Two-Army Problem," the "Coordinated Attack Problem, or, as Andreas D noted, the Two General's Problem which you've identified as your Restriction 1. The idea behind this problem is that two armies want to coordinate an attack on the enemy. They need to both attack at the same time, since each army knows that they will die if they attack on their own.

The problem is this: How does an army know their messenger, who is carrying the time intended for the coordinated attack, has reached the other army successfully? Furthermore, how can the second army be sure that the first army knows that they received the message and plans to attack? It's possible that any message between the armies doesn't arrive successfully, and thus the armies can never be sure that they're coordinated properly.

Because of this, the simplest answer may be to simply do a ping on each running game at a scheduled interval, and also whenever a user requests a refresh. You can use this information to populate your master list.

angstrom91
.. also known as 'Two-Generals-Problem' http://en.wikipedia.org/wiki/Two_Generals%27_Problem
Andreas_D
... ping only shows if the machine is still connected but not if the service is still available.
Andreas_D
@Andreas - When I said ping, I meant that his server can send a "Hey, are you still alive?" message to the hosted game server. I wasn't referring to the actual ping command.
angstrom91
OK :-) Thinking to technical ;)
Andreas_D
Clear and precise answers! Thanks a lot to both of you.
asmo
+3  A: 

Consider using some kind of heartbeat messages. Those messages ("I'm alive!") are sent regularly and if the master server doesn't get a heartbeat message from a hosted server (for a certain time), it knows, that this hosted server is unavailable.

You can even add some status parameters to this message if you need more detailed information from the hosted servers (like 'fully operational', 'going down for maintenance in 5 minutes', etc.)

Andreas_D