Skip to content

Instantly share code, notes, and snippets.

@shripadk
Created November 28, 2011 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shripadk/1400319 to your computer and use it in GitHub Desktop.
Save shripadk/1400319 to your computer and use it in GitHub Desktop.
var http = require('http');
var sockjs = require('sockjs');
var node_static = require('node-static');
var sockjs_opts = {sockjs_url: "http://127.0.0.1:8888/sockjs.js"};
var sockjs_echo = sockjs.createServer(sockjs_opts);
sockjs_echo.on('connection', function(conn) {
console.log(conn.id + ' connected');
conn.on('data', function(message) {
conn.write(message);
});
conn.on('close', function() {
});
});
// 2. Static files server
var static_directory = new node_static.Server(__dirname);
// 3. Usual http stuff
var server = http.createServer();
server.addListener('request', function(req, res) {
static_directory.serve(req, res);
});
server.addListener('upgrade', function(req,res){
res.end();
});
sockjs_echo.installHandlers(server, {prefix:'[/]echo'});
console.log(' [*] Listening on 0.0.0.0:9999' );
server.listen(9999, '0.0.0.0');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment