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);
});
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
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 tofalse
,it's can connect,but either cannot emit any msg,can you tell me why and how to fix it ,ths