xxxxxxxxxx
The "problem" is the method connect(). This is a non blocking method, which is starting the connection/handshake etc.
If you wanna send a frame right after connecting, please use the method connectBlocking().
This method blocks the thread till the connection is established (or failed).