Firefox Nodejs Websocket

I am using Aurora 17, Chrome 22 and Firefox 16 and I am trying to create a simple chat app. I am using Node 0.8.9.

Firefox is getting the error that it cannot connect giving the error

   Firefox can't establish a connection to the server at ws://localhost/.

I also tried it with the port and it have the same message

Firefox can't establish a connection to the server at ws://localhost:4444/.

Here is my code:

Server Code:

var http = require('http');
var net = require('net');

function onRequest(req, res) {
   // Does enough to render a page and javascript
}
http.createServer(onRequest).listen(4444);

var socket = new net.Socket();
socket.connect(4444, "localhost", function(){
    console.log("Socket Connected");
});

socket.on("message", function(message){
    console.log(message);
});

Client Code:

var WebSocket = window.WebSocket || window.MozWebSocket;

var connection = new WebSocket('ws://localhost:4444');

connection.onopen = function() {
    // Never runs
    alert("This never runs :(")
}

connection.onerror = function(error) {
    // Always runs here
    console.log(error)
}

I get an output that the Socket is connect from the log statement on the server but Firefox cannot connect to the socket.

On Chrome, there is no error but the "onopen" is never fired. Using connection.send("a message") does not send anything to the server and returns false.

You're creating an ordinary TCP client socket in your server code and connecting it to your HTTP server. That's not at all the same thing as creating a WebSocket server that a browser can connect to. Use a library designed for the purpose (socket.io is very commonly used, since it can fall back to alternate transports when a browser doesn't support WebSockets).