https://github.com/astro/spacesocket
WebSocket server for Node.js not invented here
https://github.com/astro/spacesocket
Last synced: 4 months ago
JSON representation
WebSocket server for Node.js not invented here
- Host: GitHub
- URL: https://github.com/astro/spacesocket
- Owner: astro
- License: mit
- Created: 2010-09-28T15:42:16.000Z (over 15 years ago)
- Default Branch: master
- Last Pushed: 2011-10-20T14:54:11.000Z (over 14 years ago)
- Last Synced: 2025-04-10T03:51:36.757Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 129 KB
- Stars: 9
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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);