server.js 630 B

1234567891011121314151617181920212223
  1. var express = require('express');
  2. var sockjs = require('sockjs');
  3. // 1. Echo sockjs server
  4. var sockjs_opts = {sockjs_url: "http://cdn.jsdelivr.net/sockjs/1.0.1/sockjs.min.js"};
  5. var sockjs_echo = sockjs.createServer(sockjs_opts);
  6. sockjs_echo.on('connection', function(conn) {
  7. conn.on('data', function(message) {
  8. conn.write(message);
  9. });
  10. });
  11. // 2. Express server
  12. var app = express.createServer();
  13. sockjs_echo.installHandlers(app, {prefix:'/echo'});
  14. console.log(' [*] Listening on 0.0.0.0:9999' );
  15. app.listen(9999, '0.0.0.0');
  16. app.get('/', function (req, res) {
  17. res.sendfile(__dirname + '/index.html');
  18. });