I have created a fairly basic client and server. In the client, once I receive the connected() message, I want to send data to the server. I do that directly in the connected() method, and it looks thusly:
1 2 3 4 5 6 7 8 9 10 11
| public void connected(byte[] arg0) { Log.l().log(Level.INFO, "Connected"); ccManager.openChannel("appMainChannel"); ByteBuffer myByteBuffer=createRequest(); try{ Thread.sleep(1000); }catch(Exception e){} ccManager.sendToServer(myByteBuffer, true); } |
The byte buffer gets created in an extra method, but that shouldn't be the problem (I have checked that it creates a correct byte array with 6 elements. Now, this works fine, on the server side I have added a SimUserDataListener which receives the
1 2
| userDataReceived(UserID from, ByteBuffer data) |
method call. However, if I remove the wait statement in the connected() method, i.e. this line:
1
| try{ Thread.sleep(1000); }catch(Exception e){} |
then it does not work, i.e. the userDataReceived() method is NOT called. What am I doing wrong?