Asking about how server can handle client disconnection
Dear sir/madam,
i'm doing my final year project and it is about a java client/server big2 game.But now i have a difficulties in dealing with the server side.
That is about how to take action on the serverside if the client suddenly disconnected.
I have read many java client/server programming scripts.But all of them doesn't mention this problem.The scrpits only assume the client side never disconnect suddenly.
I hope if you can give me some suggestions on this problem.
[506 byte] By [
horman_w] at [2007-9-27 18:58:23]

Ive just had a second socket that doesn't post information. The server just spawns a thread that calls a read() on that socket with an infinate timeout. If the read stops blocking with a -1, then the client has terminated their connection.
You could make both the client and server ping (by sending a fixed message sequence) each other at a fixed interval, then each could check for the others ping within that interval (+ some sort of tolerance level). Some of my work code uses a very similar approach.V
For my mud written in java, I used TCP/IP for the connections. When a client connects, he gets his own thread. Those threads are held in a vector in a manager class. each tick of the server does a quick run thru the vector and if the current thread/socket its on is null or !isAlive() its remove from the vector(which in turn removes it from getting any more game updates. This removal can be caused by two things. The clients disconnects by accident(kills his game, locks up has an internet connection hiccup, etc.) or he uses the games "quit" method. The quit method calls a method that does any player saving of data, etc then closes the socket, and sets it to null. thus the manager sees this and removes him frm the vecotr list on the next server tick. Seems to work great form a mud and worked really well in a multiplayer applet game I had up for a while.