开发者

Socket.io 0.7.9 connection issues

开发者 https://www.devze.com 2023-03-28 06:36 出处:网络
I am attempting to upgrade to socket.io 0.7.9 and have run in to problems. I have used the basic example from the socket.io homepage. My server is:

I am attempting to upgrade to socket.io 0.7.9 and have run in to problems.

I have used the basic example from the socket.io homepage. My server is:

var http    = require('http'),
    url     = require('url'),
    https   = require('https'),
    fs      = require('fs'),
    crypto  = require('crypto'),
    io      = require('../'),
    sys     = require(process.binding('natives').util ? 'util' : 'sys'),
    server = http.createServer(function(req, res){
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end();
    });

server.listen(80,"[MYIP]");
var io = io.listen(server), buffer=[];

io.sockets.on('connection', function (socket) {
  socket.emit('news', { hello: 'world' });
  socket.on('my other event', function (data) {
    console.log(data);
  });
});

It connects OK on some computers but not on others. It is the same across all browsers.

Does anyone know why this would happen? Could there be some local networking issue that causes this?

UPDATE It appears that the people who are unable to connect from their computers are running anti virus with real time web shields 开发者_高级运维that seem to block the connection. When they turn it off, it connects OK on some browsers...


I have been using socket.io and node.js for the last two months and some issues like yours happened to me too.

Firewalls are often a problem with the port 80, especially when used with a DNS (like in a corporate network) because they will temper with the headers of the socket packages. One work around could be to try another port. My application has an apache server on the port 80 and my websocket is on the port 843, everything is working fine on Firefox and Chrome.

You can use the xhr-polling fallback option to bypass this type of errors by adding this script:

io.set('transports', ['websocket','xhr-polling']);

xhr-polling offers less real-time performance, but is really dependable and works on most browsers and network configurations.

I hope this will help you!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号