"open" frame isn't received by client

37 views
Skip to first unread message

hel...@ciandt.com

unread,
Mar 27, 2014, 10:04:53 AM3/27/14
to soc...@googlegroups.com
Hi, folks!

I'm implementing a simple web application with websocket communication.  I'm using SockJS 0.3 in the client side, and Spring Framework 4.0.2 on server side (over Jetty 9.1.3).

When my client creates a SockJS object, I can see Spring accepting the connection and sending the "open" frame (I saw this debug Spring code).  But in client side it never comes and after a timeout the connection is closed (I can see this on server side either) and the fallback walks thru, connecting (successfully) server side using xhr-streaming.

Amazingly, if I capture the connection establishment in the server side and in this moment a send back certain messages (e.g, "100"), the "open" frame goes out as if it was stuck somewhere and the message just push it forward.  But what is really strange is that not every message sent has this positive effect.  And I couldn't find out any aspect that could segregate "good" messages from the "bad" ones - it does not seem to be its size or content.

Some examples of messages the unstuck the "open" frame:

"aaa"
"100"
"1" and "01" (two messages in a row)
"Hey!  I'm walking' here!  I'm walkin' here!"

And some don't:

"99"
"1"
"01"
"Hey!  I'm walkin' here!  I'm walkin' here!"  (note the missing 'g')
"Hey!  I'm walking' here!  I'm walking' here!"   (note the extra 'g')


My client connection code:

wsocket = new SockJS(base + "/wsocket/hello-case4");
wsocket.onmessage = function(e) {
    log("<<< " + e.data);
};
wsocket.onopen = function() {
    log("Connection opened. (" + wsocket.protocol + ")");
};
wsocket.onclose = function(e) {
    log("Connection closed.  Reason: (" + e.code + ") " + e.reason);
};


My server code:

@Configuration
@EnableWebSocket
public class HelloCase4Configurer implements WebSocketConfigurer {
    @Override
    public void registerWebSocketHandlers ( WebSocketHandlerRegistry registry ) {
        registry.addHandler( helloCases4Handler(), "/hello-case4" ).withSockJS();
    }
    @Bean
    public WebSocketHandler helloCases4Handler () {
        return new HelloCase4Handler();
    }
}

and 

public class HelloCase4Handler extends TextWebSocketHandler {
    private static final Logger LOGGER = LoggerFactory.getLogger( HelloCase4Handler.class );

    @Override
    protected void handleTextMessage ( WebSocketSession session, TextMessage message )
            throws Exception {
        LOGGER.debug( "Message received: " + message.getPayload() );
        String msg = "Hello, " + message.getPayload() + "!";
        session.sendMessage( new TextMessage( msg ) );
        LOGGER.debug( "Echo responded." );
    }

    @Override
    public void afterConnectionEstablished ( WebSocketSession session ) throws Exception {
        LOGGER.debug( "Connection opened." );

        // this unstuck "open" frame
        //session.sendMessage( new TextMessage( "Hey!  I'm walking' here!  I'm walkin' here!" ) );

        // this doesn't
        //session.sendMessage( new TextMessage( "Hey!  I'm walkin' here!  I'm walkin' here!" ) );

        // this neither
        // session.sendMessage( new TextMessage( "Hey!  I'm walking' here!  I'm walking' here!" ) );
    }

    @Override
    public void afterConnectionClosed ( WebSocketSession session, CloseStatus status )
            throws Exception {
        LOGGER.debug( "Connection closed.  Reason: ({}) {}", status.getCode(), status.getReason() );
    }
}


I couldn't find where I'm doing wrong... :-/  

Anyone has any clue?

Thanks in advance.

[]s
Heleno
Reply all
Reply to author
Forward
Message has been deleted
0 new messages