[SOLVED] Closed connection no longer has an address

So, I would like to know the address of the client when is disconnects, but by the time the connection has been removed, the HostedConnection no longer has an address:

@Override
public void connectionRemoved(Server server, HostedConnection conn) {
    LOGGER.log(Level.INFO, "Disconnected {0}", conn.getAddress());
}

This will return: Disconnected null

Is there any way around this, I feel like this is a bug, but is this intentional?

Thanks,
Trevor

conn.getAddress() is asking the underlying socket for its address. When the socket is closed, it’s address must be null. That’s just Java in this case… not anything JME is doing.

If you want the address when the connection closes then just tuck it away in the session when the connection is first established.

conn.setAttribute(“myAddress”, conn.getAddress());

…or whatever.

1 Like

Thanks, that works.

1 Like