无法在FireFox中与socket.io建立连接(xhr轮询错误)

时间:2016-09-30 17:38:07

标签: javascript node.js firefox socket.io

我正在使用socket.io 1.4.8和firefox 48.我有一个在chrome中工作正常的示例代码:

// Server
var express = require('express');
var app = express(); var fs = require('fs');
var option = {
    key: fs.readFileSync('key.pem'),
    cert: fs.readFileSync('cert.pem')
};
var https = require('https').createServer(options, app).listen(process.env.PORT || 3000);
var io = require('socket.io')(https);

io.on('connection', function(socket) {
    socket.on('login', function(username) {
        console.log('[login]', username);
    };
}

// Client
var socket = io('https://127.0.0.1:3000');
var username = 'test';
socket.emit('login', username);

但是当我在firefox中运行时,我得到了一个Error: xhr poll error.这是来自客户端的日志:

socket.io-client:url "parse https://127.0.0.1:3000" +0ms
socket.io-client "new io instance for https://127.0.0.1:3000" +3ms
socket.io-client:manager readyState closed +3ms
socket.io-client:manager "opening https://127.0.0.1:3000" +1ms
engine.io-client:socket creating transport "polling" +1ms
engine.io-client:polling polling +1ms
engine.io-client:polling-xhr xhr poll +2ms
engine.io-client:polling-xhr "xhr open GET: https://127.0.0.1:3000/socket.io/?EIO=3&transport=polling&t=LTvQYL3" +1ms
engine.io-client:polling-xhr xhr data null +1ms
engine.io-client:socket setting transport polling +2ms
socket.io-client:manager connect attempt will timeout after 8000 +1ms
socket.io-client:manager readyState opening +3ms
engine.io-client:socket socket error {"type":"TransportError","description":0} +74ms
socket.io-client:manager connect_error +1ms
socket.io-client:manager cleanup +0ms

我该如何解决此错误?感谢。

1 个答案:

答案 0 :(得分:1)

对我来说,原因是网站的自签名证书不受Firefox的信任。转到套接字URL,您应该看到一个对话框,将不受信任的站点添加到例外。