chandramanic / unitt

Automatically exported from code.google.com/p/unitt
0 stars 0 forks source link

CLOSE messages are parsed but not sent to the WebSocketObserver #31

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. connect to a server websocket implementation
2. get the server-side to initiate a close-handshake (The server implementation 
I'm currently using will initiate a close-handshake when the connection times 
out)
3. When the server-side sends a CLOSE message, the message is processed on the 
client-side but not sent to the WebSocketObserver.

This is because WebSocketConnection.closeSocket() is only called in 
WebSocketConnection.handleClose() when initiated by the client-side (and not 
when a close is initiated by the server-side).

What is the expected output? What do you see instead?
Expected: WebSocketObserver.onClose() to be called.
Observed: -
Observed in Logcat:
TAG       | MESSAGE
System.out| "Closing with (0): null"
System.out| "Message Bytes: ..."
System.out| "Fragment: ..."

What version of the product are you using? On what operating system?
 - Observed with: (initially) downloaded jar version: 0.9.2.1 and then with: svn-tagged src code version: 0.9.2
 - developing for Android API 1.6.
 - Test Client: Android 2.3.6 (Nexus One)
 - Test Server: Jetty 7.5.3 server
 - Websocket protocols: -07 / -08.

Please provide any additional information below.
I believe changing the WebSocketConnection.java code
FROM:
    protected void sendMessage( WebSocketFragment aFragment )
    {
        if ( !isClosing() || aFragment.getOpCode() == MessageOpCode.CLOSE )
        {
            try
            {
                getNetwork().write( aFragment.getFragment() );
            }
            catch ( IOException e )
            {
                sendErrorToObserver( e );
            }
        }
    }

TO:
    protected void sendMessage( WebSocketFragment aFragment )
    {
        if ( !isClosing() )
        {
            try
            {
                getNetwork().write( aFragment.getFragment() );
            }
            catch ( IOException e )
            {
                sendErrorToObserver( e );
            }
        } 
        else if ( aFragment.getOpCode() == MessageOpCode.CLOSE )
        {
            try
            {
                getNetwork().write( aFragment.getFragment() );
            }
            catch ( IOException e )
            {
                sendErrorToObserver( e );
            }
            closeSocket();
        }
    }

should solve the issue.

Thanks.

Original issue reported on code.google.com by jazzake...@gmail.com on 1 Nov 2011 at 6:24

GoogleCodeExporter commented 9 years ago
Good find! I will take a look at this over the weekend!

Original comment by joshuadmorris@gmail.com on 14 Nov 2011 at 3:11

GoogleCodeExporter commented 9 years ago
Sorry for the delay, the holidays are playing havoc with my schedule.

Original comment by joshuadmorris@gmail.com on 2 Dec 2011 at 1:21

GoogleCodeExporter commented 9 years ago
Thanks, no worries :) 

I just took a look at your changes, and looks like you may have missed one in 
WebsocketConnection.java, line 709-731:

Currently the code looks like:
  if ( !isClosing() || aFragment.getOpCode() == MessageOpCode.CLOSE )
  {
     ...
  }
  else if ( aFragment.getOpCode() == MessageOpCode.CLOSE )
  {
     ...
  }

The if statement (on ln:709) will need to be changed to: 
  if ( !isClosing() ) 
otherwise the else if statement won't ever get called.

Thanks again.

Original comment by jazzake...@gmail.com on 2 Dec 2011 at 1:44

GoogleCodeExporter commented 9 years ago
*Smacks Forehead* OOPS! Good catch!

Original comment by joshuadmorris@gmail.com on 6 Dec 2011 at 4:03

GoogleCodeExporter commented 9 years ago
No worries :)

Original comment by jazzake...@gmail.com on 7 Dec 2011 at 2:21

GoogleCodeExporter commented 9 years ago
Fixed and checked into trunk.

Original comment by joshuadmorris@gmail.com on 30 Jan 2012 at 10:11

GoogleCodeExporter commented 9 years ago

Original comment by joshuadmorris@gmail.com on 31 Jan 2012 at 6:32