KryoNet detecting disconnections.

How do I let the server disconnect connections if the client has crashed?
Cause at the moment it’s not doing that, even with the default timeout and setKeepAliveTCP.
I do not know how to take this on… I was pretty sure KryoNet did this for us.

it’s not really possible due to how tcp works.

but it’s easy to detect if server is sending data: SocketChannel.write(buffer) may return -1 or a IOException which indicates a broken client connection.

Doesn’t a kryonet server ping to all clients when setkeepalive and timeout is used?
My server doesn’t call the disconnected function of the listener when a client has crashed.

the server pings the client, the client will still answer as long he didn’t lockup too, since the kryonet Server/Client is updated on a different thread (if you call client.start();).

You could implement your own keepalive-system that asks if the application is still successfully running instead of hoping that the tcp-connection goes down with the client application.

How do I detect if the LibGDX application is still running?

Send a packet to the client.
Client-listener receives packet and sets a boolean variable “keepalive-received” to true.
Client checks in the main loop if “keepalive-received” is true.
If it is true he sends back an answer.
The server either kicks or keeps the client depending on the clients response-time
(>5 seconds => Disconnect!).

void update(float millis) {
     ... Game Logic ...
     if(keepalive-received == true) {
          send Answer to Server via tcp
          keepalive-received = false;
     ... Game Logic ...

How do YOU notice the LibGDX app is hanging? ::slight_smile:

Hhhm I was thinking of something different.
I was looking for a boolean or something that would tell me that LWJGL thread stopped working. I would then call kryonet´s stop and close methods.

ah, maybe something like :


The LWJGL client thread would stop because :

  1. You stopped it programatically
  2. An exception was thrown on the thread and you caught it in a try / catch
  3. An exception was thrown on the thread and was not caught anywhere, but you were clever and had an uncaught exception handler which caught it as a last resort.

In all these cases you know when they happen and can call the resultant kryo.dispose() method.

I surrounded the loop with a try and catch clause and closed the connection when an exception has been thrown.