Socket.IO kann keine Verbindung über https herstellen
Ich habe eine node.js-App, die socket.IO verwendet. Es funktioniert einwandfrei unter http, aber wenn Sie versuchen, über https eine Verbindung zum Socket herzustellen, geschieht nichts.
Hier ist ein Teil des Codes:
var fs = require('fs');
var ioHttp = require('socket.io').listen(8899, {
'flash policy port': -1
});
initSocket(ioHttp);
var ioHttps = require('socket.io').listen(8895, {
key: fs.readFileSync('/path/to/file/file.key'),
cert: fs.readFileSync('/path/to/file/file.crt'),
ca: [
fs.readFileSync('/path/to/file/sub.class1.server.ca.pem'),
fs.readFileSync('/path/to/file/ca.pem')
],
'flash policy port': -1
});
initSocket(ioHttps);
und dasinitSocket
Funktion:
function initSocket(io) {
io.enable('browser client minification');
io.enable('browser client etag');
io.enable('browser client gzip');
io.set('transports', [
'websocket',
'htmlfile',
'flashsocket',
'jsonp-polling'
]);
io.sockets.on('connection', function (client) {
//the connnection is handled here
});
}
Der Client verbindet sich wie folgt:
var secureConnection = false;
var port = 8899;
if (window.location.protocol === 'https:') {
port = 8895;
secureConnection = true;
}
var socket = io.connect('domain.org', {port: port, secure: secureConnection});
Wie gesagt, unter http funktioniert alles einwandfrei, aber wenn ich mich über https anmelde, bekomme ich die Meldung "Die Verbindung wurde unterbrochen". Was mache ich falsch?