Websocket is constantly shutting down

I am trying to create a chat room in a web chat that works in a browser. I did a bit of searching and found a website that shows an example of connecting to a website (www.websocket.org/echo.html). But whenever I try to use the “connect” button, it immediately “disconnects” and I can’t send a message (this only happens in Chrome). So I tried it in Firefox and it says “Error: undefined” and then “disabled”. Both browsers support websocket technology.

So, I switched to another site (http://www.tutorialspoint.com/html5/html5_websocket.htm) and copied the sample code there, saved it as ".html" and ran it in chrome. It cannot connect to websocket. Instead, he says "disconnected."

QUESTION: Why can't I connect to the websocket / why does it keep disconnecting? My version of Chrome is 21.0.1180.60.

For further reference, here is my code so far (NOTE. It is only supposed to connect and say that it is connected, not actually chat):

<!doctype html> <head> <title>Testing</title> </head> <body> <script type="text/javascript"> function confirm() { if ("WebSocket" in window) { alert("WebSocket is supported by your Browser!"); } else { alert("Your Browser does not support WebSocket Technology. Please update your Browser."); } } function sendmessage() { try { var ws = new WebSocket("ws://(ip of other user/") } catch(err) { alert("Error with creating the WebSocket") } } </script> <a href="javascript:confirm()">Run Ip Connector</a> </body> </html> 

Thanks for any help.

+4
source share
1 answer

I just tested the Echo demo at http://websocket.org/echo and it works fine using Chrome 21. Your other example seems to work fine as well. You can check it out here .

Since you are using Chrome 21, you can use the Chrome Dev tools to find out if the WebSocket handshake is passing and if you see any messages.

Is it possible that you are sitting at a router / firewall that disconnects traffic? Can you try WSS on websocket.org? (Enter the wss: //echo.websocket.org field in the Location field.)

+2
source

All Articles