You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
738 B

4 years ago
  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. });