socket.io not working in ssl

Created on 25 Aug 2017  路  2Comments  路  Source: socketio/socket.io

working fine on http
////////////// server code ///////////////////
var https = require('https');
var io = require('socket.io');
var fs = require('fs');

var privateKey = fs.readFileSync('./cleartracks.com_ssl.key');
var certificate = fs.readFileSync('./cleartracks.com_ssl.cert');
var options = {key: privateKey,cert: certificate};
var server = https.createServer(options);
server.listen(3003);
io = io.listen(server);

//////////////////// client code /////////////////
var socket = io.connect(hostname, { port:3003,secure: true, reconnect: true, rejectUnauthorized : false } );
socket.on("connect", function () {
console.log("Connected!");
});
socket.on('connect_error', function() {
console.log('Failed to connect to server');
});
socket.on('connect_failed', function() {
console.log("Sorry, there seems to be an issue with the connection!");
});
socket.on('message', function(msg){
alert(msg);
});

Most helpful comment

@darrachequesne thank you for your example,but i test it and found it cannot work well,rejectUnauthorized: true,,when i change it to false,it's can connect,but either cannot emit any msg,can you tell me why and how to fix it ,ths

All 2 comments

Please see if that example https://github.com/darrachequesne/socket.io-fiddle/tree/ssl-example fixes your issue.

@darrachequesne thank you for your example,but i test it and found it cannot work well,rejectUnauthorized: true,,when i change it to false,it's can connect,but either cannot emit any msg,can you tell me why and how to fix it ,ths

Was this page helpful?
0 / 5 - 0 ratings

Related issues

varHarrie picture varHarrie  路  3Comments

Elliot9 picture Elliot9  路  4Comments

MyMomSaysIAmSpecial picture MyMomSaysIAmSpecial  路  4Comments

MichaelJCole picture MichaelJCole  路  3Comments

jloa picture jloa  路  4Comments