first off, thanks for a great library. However, I noticed a peculiarity in the way PacketListeners are cleaned up on disconnect. Consider the following case:
How to reproduce:
Create a new connection
Add a PacketListener instance
Connect and authenticate on this connection
Disconnect (using Connection.disconnect())
Reconnect using Connection.connect() / Connection.login()
Notice that the PacketListener created at (2) is no longer called
At (4), Connection.disconnect() calls PacketReader.cleanup(), which contains the following line:
This means that the PacketListener instance created at (2) is now removed from the connection. Hence, when the connection is restored the PacketListener created at (2) will no longer be called.
Note that it’s odd that PacketReader.cleanup() should perform cleanup on the connection object. Encapsulation would dictate that a) recvListeners should be private to Connection, and b) that recvListeners should be managed by Connection exclusively.
The reason I’m using disconnect/connect is because I’m developing an Android application, where frequent IP changes due to changes in network interfaces (Wi-Fi/2G/3G) are commonplace. Sockets are not guaranteed to close on such transitions, so this should be handled by the application by listenening to events from ConnectivityManager/TelephonyManager.
Simply move the recvListeners.clear to Connection.shutdown() ?