To receive packets from the server, a PacketListener
should be implemented
and added to the connector before the connection is established. Like so:
[...] /* * Example parameters */ int port = 4123; String host = "localhost"; Encryption enc = Encryption.NONE; /* * Create connector */ Connector connector = new SocketConnector(host, port, enc); /* * Add listener */ connector.addListener(new PacketListener() { @Override public void packetRecieved(ProtocolObject packet) { // Do something here... } }); /* * Connect */ connector.connect(); [...]
Packets are delivered to the listener using a dedicated thread. In other words, there will never be concurrent delivery of multiple packets. Also, the packet ordering till be preserved.