WebSocket-compatible realtime HTTP server implemented with Node.JS
by rauchgJavaScript
Last 12 weeks · 0 commits
1 of 6 standards met
Using node v0.8.1 but this HTTP server does not compile. At first there was reference to tcp module which i replaced with net module and hence the call to create connection was changes in redis.js:47:32 to this.conn = new tcp.Stream(); Please update the websocket.js and redis.js to compile on node v0.8.1
Quote from Node.js doc: Node supports 3 string encodings. UTF-8 ("utf8"), ASCII ("ascii"), and Binary ("binary"). "ascii" and "binary" only look at the first 8 bits of the 16bit JavaScript string characters. Because there no way to write "0xFF" byte in UTF-8 encoding, the following code is invalid: this.socket.write('\u0000' + data + '\uffff'); It could be replaced with: this.socket.write('\u0000' + data, 'utf8'); this.socket.write('\uffff', 'binary'); Or better (warning - uses internal, undocumented Node.js API): var Buffer = require('buffer').Buffer; var bytes = Buffer.byteLength(data, 'utf8') + 2; var buffer = new Buffer(bytes); buffer[0] = 0; buffer.utf8Write(data, 1); buffer[bytes-1] = 0xff; this.socket.write(buffer);
Repository: rauchg/node.websocket.js. Description: WebSocket-compatible realtime HTTP server implemented with Node.JS Stars: 268, Forks: 25. Primary language: JavaScript. Languages: JavaScript (98.4%), CSS (1.6%). Homepage: http://devthought.com/blog/2009/12/nodejs-and-the-websocket-protocol/ Open PRs: 0, open issues: 4. Last activity: 11y ago. Community health: 28%. Top contributors: rauchg, jgoulah, adamac, tomByrer.
I'm trying out node.websocket with latest chromium builds, but its not quite working in this scenario: 1. Open a page with an websocket that periodically sends data to the browser (eg. it sends the current date 1 time per second, like the runserver.js that ships with node.websocket). 2. Open the same page in a new tab. 3. Close the first tab (by clicking the tab close button). 4. See that the remaining tab window stops receiving data in the web socket. I've opened a ticket with chromium (https://code.google.com/p/chromium/issues/detail?id=30668) and another with webkit (https://bugs.webkit.org/show_bug.cgi?id=32774), but maybe this is really a problem with node.websocket because I've tried an equivalent test against a ruby web socket server (http://github.com/igrigorik/em-websocket) and it worked fine.