Skip to content
WebSocket server for Node.js not invented here
JavaScript
Find file
Latest commit e04ffc6 Oct 20, 2011 @astro Update package.json
Failed to load latest commit information.
lib connection: send() as write Sep 29, 2010
speedtest
test untabify all files Sep 29, 2010
LICENSE README & LICENSE Sep 29, 2010
README.md
package.json

README.md

WebSockets From Space*

\* There are no users in space, only astronauts with the latest browser. Therefore no graceful fallback is attempted.

API

Setup

var server = http.createServer(...);
server.listen(port);

require('spacesocket').attach(server, function(conn) {
    dealWithWebSocket(conn);
});

Reading

conn.on('data', function(msg) {
    doStuffWithString(msg);
});

Writing

conn.write('Hello, World');

Closure

conn.end();

Buffer control

conn.on('drain', function() {
    // socket write queue is empty,
    // send until queueing again:
    while(conn.send(data)) { }
});

// Throttle sender for 1s:
conn.pause();
setTimeout(function() { conn.resume(); }, 1000);
Something went wrong with that request. Please try again.