EsotericSoftware / kryonet

TCP/UDP client/server library for Java, based on Kryo
BSD 3-Clause "New" or "Revised" License
1.81k stars 416 forks source link

dispatchListener removes connections too early #84

Open wwiillllii opened 9 years ago

wwiillllii commented 9 years ago
    public void disconnected (Connection connection) {
        removeConnection(connection);
        Listener[] listeners = Server.this.listeners;
        for (int i = 0, n = listeners.length; i < n; i++)
            listeners[i].disconnected(connection);
    }

shouldn't the connection be removed only after all the listeners were called? if the connection is removed before, the other listeners may not have the data the need, for example the connection's address.

NathanSweet commented 9 years ago

If a disconnect event occurred, the disconnect has already happened. Maybe a listener sends an object to all connections, in which case it should not send to the disconnected connection.

The connection doesn't have an address because it isn't connected. You could always store additional information for a connection, such as the last connected address.

On Wed, Feb 11, 2015 at 8:30 PM, wwiillllii notifications@github.com wrote:

public void disconnected (Connection connection) {
    removeConnection(connection);
    Listener[] listeners = Server.this.listeners;
    for (int i = 0, n = listeners.length; i < n; i++)
        listeners[i].disconnected(connection);
}

shouldn't the connection be removed only after all the listeners were called? if the connection is removed before, the other listeners may not have the data the need, for example the connection's address.

— Reply to this email directly or view it on GitHub https://github.com/EsotericSoftware/kryonet/issues/84.