Sunday 15 May 2011

websocket - Android - Autobahn web socket communication -


I am working on web socket communication with Autobon library. If I have a problem after joining the server, then the message should be sent again without a connection. But the message is sent with various connections, which connects to the server all the time to send the message. The public class increases the WebSocket_Connector activity {Personal Static Last StringTAG = "ECHOCLIENT"; Private Static Last String TAG1 = "My App"; Public End WebSocket Connection mConnection = New WebSocketConnection (); Private string tmpString = ""; Public Zero Connect (Last String Vases) {Log D. (Tag, "connect to:" + wsuri); {MConnection.connect (wsuri, new WebSocketHandler) {@Override Open at Public Zero) {Log D. (Tag, "status: connect" + wsuri); Log D (TAG, "Connection successful! \ N"); MConnection.sendTextMessage (tmpString); TmpString = ""} @Override Test Message (String Payload) on Public Zero {Log D. (TAG, "echo:" + payload);} @ override public closed on zero (int code, cause of string) {log d. (Tag, "connection closed.");}}); } Catch (WebSocketException e) {log d. (Tag, E.Stosting ()); }} Public Zero Send Message (String Message) {If (mConnection.isConnected ()) {Log D. (TAG1, "Message is sent:" + Message); MConnection.sendTextMessage (message); } Else {tmpString = message; Connect ("ws: //192.168.3.100: 7681"); }}}

This is the code I have, and ... when you see the "sendMessage" method, it does not always go to 'else' if there is no loop. Any suggestions 'experts' please ..?

I do not know what package name you are working with for the Websocket, The question has to be made available to get a reliable answer. But say this is something like this: Note: I have not seen there is connect () method, but suppose it has been added somewhere else.

You can see from the source that associated with Open () (line 88) first is called = true; On line (91) If this member is used as a result of var isConnected (), your code will always follow the "and" part of the condition.

I would advise to follow the websocket api and its usage pattern.

No comments:

Post a Comment