Socket IO WebSocket requests blocked by corporate

2019-04-29 11:41发布

问题:

What is the solution to using socket.io module from behind corporate firewall/proxy? This is the code I am using.

// setup express server
var app = express()
var serv = http.createServer(app);
serv.listen(80);

// setup socket io - listens in on express store as well for sessions
var io = require('socket.io').listen(serv);

回答1:

I had a similar issue and I ended up disabling websocket entirely:

io.configure('production', function(){
  io.set('transports', ['xhr-polling']);
});

XHR-polling works everywhere, but has a much bigger overhead for everyone (even if only 5% of users actually need it).

Good news is, the upcoming 1.0 version of Socket.IO will fix this:

Unlike the previous Socket.IO core, it always establishes a long-polling connection first, then tries to upgrade to better transports that are "tested" on the side.

Check it here: https://github.com/LearnBoost/engine.io