onTextMessage problem

#1

Hi, I'm implementing an Android application which uses Autobahn's API
for websocket communication. I had no reasons to complain, until now
that my websocket is not working properly. Namely it's
WebSocketHanlder's onTextMessage is not being called when the server
sends a message. The differences between my earlier working versions
and this last one are not related with the connection.

Here is the code related with the connection (it has the same
structure as the echo client):

private final WebSocketConnection mConnection = new
WebSocketConnection();

     private void start() {

        final String wsuri = "ws://" + mHostname + ":" + mPort;

        Log.i(TAG, "Status: Connecting to " + wsuri + " ..");

        try {
           mConnection.connect(wsuri, new WebSocketHandler() {
              @Override
              public void onOpen() {
                Log.i(TAG + " onOpen()", "Status: Connected to " +
wsuri);
                _activityListener.informActivity("Status: Connected to "
+ wsuri);

              }

              @Override
              public void onTextMessage(String payload) {

                interpretReceivedMsg(payload);
                Log.i(TAG+ " onTextMessage()", "Message received. Size:
" +payload.length());
              }

              @Override
              public void onClose(int code, String reason) {
                Log.i(TAG+ " onClose()", "WS connection lost/ended.");
                _activityListener.informActivity("Status: WS connection
lost/ended.");
              }
           });
        } catch (WebSocketException e) {

           Log.d(TAG, e.toString());
           _activityListener.informActivity(e.getMessage());
        }
     }

I don't really know what happens since the connection is opened but no
server message reaches the onTextMessage. Has this happened to anyone
else? Where and how should I look for the problem?

Thank you in advance,

Michel

0 Likes

#2

Hi Michel,

2 things:

First, please use current sources (head@master) from repo

https://github.com/tavendo/AutobahnAndroid

[We had a JAR published for some time .. totally outdated .. still need
a sane, automated, cmd line JAR builder]

Second, when you use latest sources, in many (most?) classes there is
debug switched on:

public class WebSocketConnection {

    private static final boolean DEBUG = true;
    private static final String TAG = WebSocketConnection.class.getName();

It would help if you attached the logcat output .. maybe there is something to be seen ..

\Tobias

···

Am 19.03.2012 17:47, schrieb Michel C�novas:

Hi, I'm implementing an Android application which uses Autobahn's API
for websocket communication. I had no reasons to complain, until now
that my websocket is not working properly. Namely it's
WebSocketHanlder's onTextMessage is not being called when the server
sends a message. The differences between my earlier working versions
and this last one are not related with the connection.

Here is the code related with the connection (it has the same
structure as the echo client):

  private final WebSocketConnection mConnection = new
WebSocketConnection();

     private void start() {

        final String wsuri = "ws://" + mHostname + ":" + mPort;

        Log.i(TAG, "Status: Connecting to " + wsuri + " ..");

        try {
           mConnection.connect(wsuri, new WebSocketHandler() {
              @Override
              public void onOpen() {
                Log.i(TAG + " onOpen()", "Status: Connected to " +
wsuri);
                _activityListener.informActivity("Status: Connected to "
+ wsuri);

              }

              @Override
              public void onTextMessage(String payload) {

                interpretReceivedMsg(payload);
                Log.i(TAG+ " onTextMessage()", "Message received. Size:
" +payload.length());
              }

              @Override
              public void onClose(int code, String reason) {
                Log.i(TAG+ " onClose()", "WS connection lost/ended.");
                _activityListener.informActivity("Status: WS connection
lost/ended.");
              }
           });
        } catch (WebSocketException e) {

           Log.d(TAG, e.toString());
           _activityListener.informActivity(e.getMessage());
        }
     }

I don't really know what happens since the connection is opened but no
server message reaches the onTextMessage. Has this happened to anyone
else? Where and how should I look for the problem?

Thank you in advance,

Michel

0 Likes

#3

Hi, I remembered that I had something similar happen to me a couple of
months ago. Turned out it had to do with onBinaryMessage or
onRawTextMessage. I believe it was the latter. Take a look at the file
WebSocketConnection.java. I can't remember how I fixed it. If you're
having a very hard time with this, let me know and I'll do a diff on
the source code to see if I changed something in Autobahn's java code,
or on the server.

···

On Mar 19, 5:47 pm, Michel Cânovas <michelm...@gmail.com> wrote:

Hi, I'm implementing an Android application which uses Autobahn's API
for websocket communication. I had no reasons to complain, until now
that my websocket is not working properly. Namely it's
WebSocketHanlder's onTextMessage is not being called when the server
sends a message. The differences between my earlier working versions
and this last one are not related with the connection.

Here is the code related with the connection (it has the same
structure as the echo client):

private final WebSocketConnection mConnection = new
WebSocketConnection();

       private void start\(\) \{

          final String wsuri = &quot;ws://&quot; \+ mHostname \+ &quot;:&quot; \+ mPort;

          Log\.i\(TAG, &quot;Status: Connecting to &quot; \+ wsuri \+ &quot; \.\.&quot;\);

          try \{
             mConnection\.connect\(wsuri, new WebSocketHandler\(\) \{
                @Override
                public void onOpen\(\) \{
                    Log\.i\(TAG \+ &quot; onOpen\(\)&quot;, &quot;Status: Connected to &quot; \+

wsuri);
_activityListener.informActivity("Status: Connected to "
+ wsuri);

                \}

                @Override
                public void onTextMessage\(String payload\) \{

                    interpretReceivedMsg\(payload\);
                    Log\.i\(TAG\+ &quot; onTextMessage\(\)&quot;, &quot;Message received\. Size:

" +payload.length());
}

                @Override
                public void onClose\(int code, String reason\) \{
                    Log\.i\(TAG\+ &quot; onClose\(\)&quot;, &quot;WS connection lost/ended\.&quot;\);
                    \_activityListener\.informActivity\(&quot;Status: WS connection

lost/ended.");
}
});
} catch (WebSocketException e) {

             Log\.d\(TAG, e\.toString\(\)\);
             \_activityListener\.informActivity\(e\.getMessage\(\)\);
          \}
       \}

I don't really know what happens since the connection is opened but no
server message reaches the onTextMessage. Has this happened to anyone
else? Where and how should I look for the problem?

Thank you in advance,

Michel

0 Likes

#4

Thank you for your suggestions. Meanwhile, though I followed them, the
app suffered profound modifications, some of them regarding the
threading scheme, and now the error is gone. Don't know exactly what
did the trick, but the ws is now receiving messages from the server
again. Now I have other errors, but since they are not related to this
one, I'll start another thread of discussion.

Thank you again,

Michel

···

On 19 Mar, 20:10, Tobias Oberstein <tobias.o...@gmail.com> wrote:

Hi Michel,

2 things:

First, please use current sources (head@master) from repo

https://github.com/tavendo/AutobahnAndroid

[We had a JAR published for some time .. totally outdated .. still need
a sane, automated, cmd line JAR builder]

Second, when you use latest sources, in many (most?) classes there is
debug switched on:

public class WebSocketConnection {

private static final boolean DEBUG = true;
private static final String TAG = WebSocketConnection\.class\.getName\(\);

It would help if you attached the logcat output .. maybe there is
something to be seen ..

\Tobias

Am 19.03.2012 17:47, schrieb Michel C novas:

> Hi, I'm implementing an Android application which uses Autobahn's API
> for websocket communication. I had no reasons to complain, until now
> that my websocket is not working properly. Namely it's
> WebSocketHanlder's onTextMessage is not being called when the server
> sends a message. The differences between my earlier working versions
> and this last one are not related with the connection.

> Here is the code related with the connection (it has the same
> structure as the echo client):

> private final WebSocketConnection mConnection = new
> WebSocketConnection();

> private void start() {

> final String wsuri = "ws://" + mHostname + ":" + mPort;

> Log.i(TAG, "Status: Connecting to " + wsuri + " ..");

> try {
> mConnection.connect(wsuri, new WebSocketHandler() {
> @Override
> public void onOpen() {
> Log.i(TAG + " onOpen()", "Status: Connected to " +
> wsuri);
> _activityListener.informActivity("Status: Connected to "
> + wsuri);

> }

> @Override
> public void onTextMessage(String payload) {

> interpretReceivedMsg(payload);
> Log.i(TAG+ " onTextMessage()", "Message received. Size:
> " +payload.length());
> }

> @Override
> public void onClose(int code, String reason) {
> Log.i(TAG+ " onClose()", "WS connection lost/ended.");
> _activityListener.informActivity("Status: WS connection
> lost/ended.");
> }
> });
> } catch (WebSocketException e) {

> Log.d(TAG, e.toString());
> _activityListener.informActivity(e.getMessage());
> }
> }

> I don't really know what happens since the connection is opened but no
> server message reaches the onTextMessage. Has this happened to anyone
> else? Where and how should I look for the problem?

> Thank you in advance,

> Michel

0 Likes

#5

do u have any idea how to pass header in connection method ?

···

On Monday, 19 March 2012 22:17:32 UTC+5:30, Michel Cânovas wrote:

Hi, I’m implementing an Android application which uses Autobahn’s API

for websocket communication. I had no reasons to complain, until now

that my websocket is not working properly. Namely it’s

WebSocketHanlder’s onTextMessage is not being called when the server

sends a message. The differences between my earlier working versions

and this last one are not related with the connection.

Here is the code related with the connection (it has the same

structure as the echo client):

private final WebSocketConnection mConnection = new

WebSocketConnection();

       private void start() {



          final String wsuri = "ws://" + mHostname + ":" + mPort;



          Log.i(TAG, "Status: Connecting to " + wsuri + " ..");



          try {

             mConnection.connect(wsuri, new WebSocketHandler() {

                @Override

                public void onOpen() {

                        Log.i(TAG + " onOpen()", "Status: Connected to " +

wsuri);

                        _activityListener.informActivity("Status: Connected to "
  • wsuri);

                  }
    
    
    
                  @Override
    
                  public void onTextMessage(String payload) {
    
    
    
                          interpretReceivedMsg(payload);
    
                          Log.i(TAG+ " onTextMessage()", "Message received. Size:
    

" +payload.length());

                }



                @Override

                public void onClose(int code, String reason) {

                        Log.i(TAG+ " onClose()", "WS connection lost/ended.");

                        _activityListener.informActivity("Status: WS connection

lost/ended.");

                }

             });

          } catch (WebSocketException e) {



             Log.d(TAG, e.toString());

             _activityListener.informActivity(e.getMessage());

          }

       }

I don’t really know what happens since the connection is opened but no

server message reaches the onTextMessage. Has this happened to anyone

else? Where and how should I look for the problem?

Thank you in advance,

Michel

0 Likes