SockJS-nodeNode.JS Server
SockJS-node is a Node.js server side counterpart of SockJS-client browser library written in CoffeeScript.
To install sockjs-node
run:
npm install sockjs
(If you see rbytes
dependecy failing, don't worry, it's optional, SockJS-node will work fine without it.)
An simplified echo SockJS server could look more or less like:
var http = require('http'); var sockjs = require('sockjs'); var echo = sockjs.createServer(); echo.on('connection', function(conn) { conn.on('data', function(message) { conn.write(message); }); conn.on('close', function() {}); }); var server = http.createServer(); echo.installHandlers(server, {prefix:'/echo'}); server.listen(9999, '0.0.0.0');
评论