所以我切換到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);
什麼是實際錯誤? –
套接字沒有連接.. –
也是我連接丟失! –