简体   繁体   English

Socket.IO连接事件无法正确触发

[英]Socket.IO Connection Event not firing properly

For some reason, the connection event fires when I connect from my local machine. 由于某些原因,当我从本地计算机连接时会触发连接事件。 But when I connect from another machine, it serves the socket io but it doesn't spit out any feedback and non of the console output, that is supposed to fire, does. 但是,当我从另一台计算机连接时,它为套接字io提供了服务,但是它不会吐出任何反馈,而且应该触发的非控制台输出也不会。

The following is run when the server is started: 启动服务器时,将运行以下命令:

startSocketService : function(http,fn){
    ar pub = redis.createClient();
    var sub = redis.createClient();
    var client = redis.createClient();
    var service = io.listen(http); //http is just the ExpressJS service
    service.enable('browser client minification');
    service.enable('browser client etag');
    service.set('transports', [
        'websocket'
        , 'flashsocket'
        , 'htmlfile'
        , 'xhr-polling'
        , 'jsonp-polling'
    ]);
    service.set('store',new RedisStore({
        redisPub: pub,
        redisSub: sub,
        redisClient: client
    }));
    console.log('Socket service listening on port '+config.ports.http);
    service.sockets.on('connection',function(socket){
        console.log("Incoming Socket Connection -> ",socket.id);
        if(typeof fn === 'function'){fn(socket);} //this is just a callback
    });
}

That console.log, as well as all console.log's in the callback, only fire when I connect from 127.0.0.1. 该console.log以及回调中的所有console.log,仅当我从127.0.0.1连接时才会触发。 Any outside connections do not output to the console, yet they seem to be working. 任何外部连接都不会输出到控制台,但它们似乎可以正常工作。 They also seem to have a unique socket id. 它们似乎还具有唯一的套接字ID。 This still worries me. 这仍然让我担心。 I can't test anything with it like this! 我无法像这样测试任何东西!

The problem was client side. 问题出在客户端。 I was pointing to 127.0.0.1, so on other machines they were pointing to their own local instance. 我指的是127.0.0.1,因此在其他计算机上,他们指的是自己的本地实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM