server.js 738 B

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