1
ws = new MozWebSocket("ws://localhost:8080/html5WebSocket/mywebsocket.do");

I used the code above to execute websocket request but found that the connection was closed immediately with the method onclose called.

ws.onclose = function(evt) {
        alert("close");
    };

The net tab of firebug shows the request url from browser to tomcat is http://localhost:8080/html5WebSocket/mywebsocket.do. I expected the url to be ws://localhost:8080/html5WebSocket/mywebsocket.do.

What have I done wrong?

1
  • This should be tagged as JavaScript, not Java, two completely different things. Retagged for you Commented Aug 24, 2012 at 5:34

3 Answers 3

2

MozWebSocket was used in Firefox 6-10, if you're using a newer Version, use WebSocket for as constructor method.

Sign up to request clarification or add additional context in comments.

1 Comment

I tested this example in firefox 14.Maybe i need to change it to firefox 10.thanks!
0

It is normal to see a connection to http://... when using web sockets, since the web socket handshake is otherwise indistinguishable from an HTTP "upgrade" request.

The problem is likely server-side, not client-side.

Comments

0

I use the "WebSocket"-class in javascript. It works in Safara, Firefox and Chrome. Here is an example:

var ws = new WebSocket(wsUrl);
ws.onopen = function() {
    ...
};
ws.onmessage = function(evt) {
   ...
};
ws.onclose = function() {
   ...
};

On serverside i work with Tomcat & Jetty-Websocket (http://wiki.eclipse.org/Jetty/Feature/WebSockets)

1 Comment

Why it can't works in the latest version of IE 9 and Chrome 24 according to my test?I nearly used all the approaches.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.