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.
source share