所以我切换到HTTPS,一切都很好地运行插座。切换到HTTPS后无法连接到服务器
如果我尝试访问的网站与HTTP,套接字连接,但如果我尝试使用HTTPS连接,我得到:
在控制台的错误:
Failed to load resource: net::ERR_CONNECTION_CLOSED
Failed to load resource: net::ERR_CONNECTION_CLOSED
Failed to load resource: net::ERR_CONNECTION_CLOSED
Failed to load resource: net::ERR_CONNECTION_CLOSED
前端:
function connect()
{
if (!SOCKET)
{
var hash = getCookie('hash');
if (hash == "") {
//$.notify('You must login!', 'success');
}
if (hash != "") {
$.notify('Connecting...', 'success');
}
SOCKET = io(':3001');
SOCKET.on('connect', function(msg) {
if (hash != "") {
//$.notify('Connected!', 'success');
}
SOCKET.emit('hash', {
hash: hash
});
$('#games tr').remove();
});
SOCKET.on('connect_error', function(msg) {
$.notify('Connection lost!', 'success');
});
SOCKET.on('message', function(msg) {
onMessage(msg);
});
SOCKET.on('disconnect', function(m) {
SOCKET.emit('disconnect', {
uhash: hash
});
});
}
else
{
console.log("Error: connection already exists.");
}
}
的Node.js /后端
var httpsOptions = {
cert: fs.readFileSync("/path/to/cert/cert.pem"),
ca: fs.readFileSync("/path/to/cert/chain.pem"),
key: fs.readFileSync("/path/to/cert/privkey.pem"),
}
var server = require('https').createServer(httpsOptions);
var io = require('socket.io').listen(server);
server.listen(3001);
什么是实际错误? –
套接字没有连接.. –
也是我连接丢失! –