I've been trying to make a websocket chat room that runs in-browser. I've done a bit of googling around and have found a website that provides an example websocket connection (www.websocket.org/echo.html). But whenever I try their "connect" button, it says "disconnected" straight away, and I cannot send a message (this only occurs on Chrome). So I tried it on Firefox, and it says "Error: undefined" and then "disconnected". Both browsers support websocket technology.
So I went to another website (http://www.tutorialspoint.com/html5/html5_websocket.htm) and copied there example code, saved it as ".html" and ran it in chrome. It cannot connect to the websocket. Instead, it says "disconnected".
QUESTION: Why can I not connect to a websocket/why does it keep disconnecting? My Chrome version is 21.0.1180.60.
For further reference, here is my code so far (NOTE: This only is supposed to connect and say that it has 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.