0

我正在使用带有节点的套接字 io 来管理聊天应用程序

我可以很容易地连接到我的套接字,但是,当我从其他机器连接时,客户端不会收到任何内容。

在其他机器上,没有禁用杀毒和防火墙。(我使用谷歌浏览器和歌剧和Windows 7)

真正有趣的是我可以用我的手机很好地连接到套接字!

当那台机器连接到系统时,我可以在控制台中看到这个调试

 info  - socket.io started
   debug - served static content /socket.io.js
   debug - served static content /socket.io.js
   debug - client authorized
   info  - handshake authorized gu63jD6tYNPCf7JO72U0
   debug - setting request GET /socket.io/1/websocket/gu63jD6tYNPCf7JO72U0
   debug - set heartbeat interval for client gu63jD6tYNPCf7JO72U0
   debug - client authorized for 
   debug - websocket writing 1::
   **debug - websocket writing 5:::{"name":"ready","args":[{"msg":"hi"}]}**
   debug - setting request GET /socket.io/1/xhr-polling/gu63jD6tYNPCf7JO72U0?t=1374596975155
   debug - setting poll timeout
   debug - discarding transport
   debug - cleared heartbeat interval for client gu63jD6tYNPCf7JO72U0
   debug - setting request GET /socket.io/1/jsonp-polling/gu63jD6tYNPCf7JO72U0?t=1374596985158&i=0
   debug - setting poll timeout
   debug - discarding transport
   debug - clearing poll timeout

我用它连接到我的网站:

var socket = io.connect('192.168.1.101:900');

机器找不到 404 未找到,或者错误,只是方法没有触发...

如您所见,客户端应该接收就绪,但没有得到,问题出在哪里?

服务器源:

var express = require('/usr/local/lib/node_modules/express'),
        app = express()
        , http = require('http')
        , server = http.createServer(app)
        , io = require('/usr/local/lib/node_modules/socket.io').listen(server);

// listen for new web clients:
server.listen(900, function() {
    //console.log(this);
});


// routing
app.get('/', function(req, res) {
    res.end('It works');
});

io.sockets.on('connection', function(socket) {

    socket.emit('ready', {msg: 'hi'});
}

客户

    var socket = io.connect('192.168.1.101:900');
    console.log('connecting');

    socket.on('error', function(data) {
        console.log(data || 'error');
    });

    socket.on('connect_failed', function(data) {
        console.log(data || 'connect_failed');
    });

    // on connection to server, ask for user's name with an anonymous callback
    socket.on('connect', function() {

        alert('work');
    });

    socket.on('ready', function() {

        alert('work');
    });
4

0 回答 0