am aware socket.io websockets
My implementation throws an error every time (in chrome and safari). According to wikipedia it is up to spec based on the input output values they supply here.
I don't know how to debug this any farther because the error messages in chrome and ff provide no information about why they failed (or do they?)
SERVER --
var domain = "http://www.mysitee.com/";
domain = "localhost/";
var port = 80;
var fs = require("fs");
var util = require("util");
var http = require("http");
var crypto = require("crypto");
var net = require("net");
var server = http.createServer();
var start = new Date().getTime();
var indexFile = fs.readFileSync(__dirname + "/index.htm");
var opened = new Date().getTime();
indexFile = indexFile.toString() + "\
<!-- read time: " + (opened - start) + "ms --><br/>\r\n\
<!-- index size: " + (indexFile.length / 1024).toFixed(2) + "kb -->";
server.on("upgrade", function (req, socket, upgradeHead) {
var crypto = require("crypto");
var shasum = crypto.createHash("sha1");
shasum.update(req.headers["sec-websocket-key"]);
shasum.update("258EAFA5-E914-47DA-95CA-C5AB0DC85B11");
var hash = shasum.digest("hex");
console.log("hex:" + hash);
var myVal = new Buffer(hash, "hex").toString('base64');
console.log("myVal: " + myVal);
socket.setNoDelay(true);
socket.write("\
HTTP/1.1 101 Switching Protocols\r\n\
Upgrade: websocket\r\n\
Connection: Upgrade\r\n\
Sec-WebSocket-Accept: " + myVal + "\r\n\
Sec-WebSocket-Protocol: chat\r\n\r\n"
);
});
server.on("request", function (req, res) {
if (req.url === "/e")
process.exit();
console.log("request " + indexFile.substring(0, 50));
res.write(indexFile);
res.end();
});
server.on("connection", function () {
console.log("connection");
});
server.on("connect", function () {
console.log("connect");
});
server.on("checkContinue", function () {
console.log("check continue");
});
server.on("close", function () {
console.log("close");
});
server.on("clientError", function (e) {
console.log("client error");
});
server.listen(port);
CLIENT--
var connection = new WebSocket("ws:localhost:80");
connection.onopen = function () { alert("OPEN"); };
connection.message = function () { alert("MESSAGE"); };
connection.onerror = function (e) { alert("ERROR"); console.log(e); };
connection.onclose = function () { alert("CLOSE"); };