users@glassfish.java.net

Re: Websockets with 4.0b81 - pending / half-open connections

From: Pavel Bucek <pavel.bucek_at_oracle.com>
Date: Tue, 26 Mar 2013 23:51:16 +0100

Hi Bjoern,

can you please try running Tyrus sample? For example this one:

http://java.net/projects/tyrus/sources/source-code-repository/show/trunk/samples/simplelife?rev=549
(includes simple js client)

should do what you want. (you might need to use newer glassfish build,
there was new release of websocket-api in the meantime).

Also, you can use users_at_tyrus.java.net mailing list.

Regards,
Pavel

On 3/26/13 9:22 PM, bjoern.wuest_at_gmx.net wrote:
> 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
>