Get if HostedConnection is closed


I have a HostedConnection that is a client, and I would like to check if that HostedConnection has still got a full connection or if it has closed.

I can’t actually find any documentation, but apologies if there is some.

Hello joehot200,
there is no method defined to check connection states for a HostedConnection. But on the client side you easily can check if the client is connected or not.


Hopefully I could help you.

I’m trying to get from the server if a client is still connected or not.

As clients could crash, I cannot rely on them informing the server that they are disconnecting.

So I need a way from the server to know if a client is connected.

Alright, on server side you can implement a ConnectionListener

public void connectionAdded(Server server, HostedConnection conn) {
// Code that will be executed when a client has been connected to the server

public void connectionRemoved(Server server, HostedConnection conn) {
// Code that will be executed when a connection (client) has been closed

Where would I do this? I tried making my main server class implement ConnectionListener and put it there, but it didn’t seem to have any effect when I put the methods in.

Did you add the listener to the server instance like this:

1 Like

Yay, it worked.

Thanks for the help!