Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ncr/node.ws.js
WARNING: NO LONGER ACTIVELY MAINTAINED (unless you want to help with a pull request :), use http://einaros.github.com/ws/ instead. Basic Web Sockets Server for node.js with similar interface to tcp.createServer(...)
https://github.com/ncr/node.ws.js
Last synced: 3 months ago
JSON representation
WARNING: NO LONGER ACTIVELY MAINTAINED (unless you want to help with a pull request :), use http://einaros.github.com/ws/ instead. Basic Web Sockets Server for node.js with similar interface to tcp.createServer(...)
- Host: GitHub
- URL: https://github.com/ncr/node.ws.js
- Owner: ncr
- Created: 2009-12-23T15:03:19.000Z (almost 15 years ago)
- Default Branch: master
- Last Pushed: 2012-03-16T15:00:16.000Z (over 12 years ago)
- Last Synced: 2024-06-22T22:05:09.272Z (6 months ago)
- Language: JavaScript
- Homepage:
- Size: 120 KB
- Stars: 180
- Watchers: 9
- Forks: 39
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Minimal WebSockets for node.js
* Compatible with node v0.1.91
* Interface is almost the same as tcp.createServer(...)
* Flash policy file requests are handled (hardcoded, permissive), see http://github.com/gimite/web-socket-js## Example - WebSocket server
var sys = require("sys"),
ws = require("./ws");ws.createServer(function (websocket) {
websocket.addListener("connect", function (resource) {
// emitted after handshake
sys.debug("connect: " + resource);// server closes connection after 10s, will also get "close" event
setTimeout(websocket.end, 10 * 1000);
}).addListener("data", function (data) {
// handle incoming data
sys.debug(data);// send data to client
websocket.write("Thanks!");
}).addListener("close", function () {
// emitted when server or client closes connection
sys.debug("close");
});
}).listen(8080);## Example - Secure WebSocket server
var sys = require("sys"),
ws = require("./ws"),
crypto = require('crypto'),
fs = require("fs");var privateKey = fs.readFileSync('privatekey.pem').toString();
var certificate = fs.readFileSync('certificate.pem').toString();var credentials = crypto.createCredentials({key: privateKey, cert: certificate});
ws.createSecureServer(function (websocket) {
websocket.addListener("connect", function (resource) {
// emitted after handshake
sys.debug("connect: " + resource);// server closes connection after 10s, will also get "close" event
setTimeout(websocket.end, 10 * 1000);
}).addListener("data", function (data) {
// handle incoming data
sys.debug(data);// send data to client
websocket.write("Thanks!");
}).addListener("close", function () {
// emitted when server or client closes connection
sys.debug("close");
});
}, credentials).listen(8080);### Author
Jacek Becela, Samuel Cyprian