users@glassfish.java.net

Websockets with 4.0b81 - pending / half-open connections

From: <bjoern.wuest_at_gmx.net>
Date: Tue, 26 Mar 2013 20:22:37 +0000 (GMT)

Good evening,


I am trying html5 websocket technology with Glassfish. I use the
Glassfish 4 b81 with JSR-356 support built-in. Yet, I fail to actually
really open a websocket. In google Chrome, it says that the websocket
connection is pending. When I try to send something from the browser to
the server via the websocket, I will get invalidDOMException with code
11. Sending something from the server to the client does not result in
any exception (or even log message) but message is never received at
the browser.


Here is my server-side code:

@ServerEndpoint(value="/ws") public class CWSHandler {
        @OnOpen public void open(Session S) {
                System.out.println("### NEW CONNECTION OPENED ###");
        }
        
        @OnMessage public void process(ByteBuffer Data, Session S) {
                System.out.println("### GOT MESSAGE ###");
        }
        
        @OnError public void error(Session S, Throwable Cause) {
                System.out.println("### HAVE ERROR ###");
                if (null != Cause) { Cause.printStackTrace(); }
        }
        
        @OnClose public void close(Session S, CloseReason Reason) {
                System.out.println("### CONNECTION CLOSED ### " +
Reason.getReasonPhrase());
        }
}


And here is the client code:

var commChannel = new WebSocket(wsURI);
commChannel.onerror = function (evt) { console.log("Error: " + evt); };
commChannel.onopen = function (evt) {
        console.log("Connection opened: " + evt);
        try { commChannel.send("Hello world"); }
        catch (err) { console.log(err); }
};
commChannel.onclose = function (evt) { console.log("Connection closed:
" + evt); };
commChannel.onmessage = function (evt) { console.log("Received message
from websocket: " + evt); };



The output on the server is:

[2013-03-26T20:23:34.949+0100] [glassfish 4.0] [INFO] [] [] [tid:
_ThreadID=30 _ThreadName=Thread-3] [timeMillis: 1364325814949]
[levelValue: 800] [[
  ### NEW CONNECTION OPENED ###]]


The output on the client is:
Connection opened: [object Event] line 4
Error: InvalidStateError: DOM Exception 11 line 6



What am I missing?

Regards
  Bjoern