I have a problem with node.js, socket.io and a new SSL certificate i implemented. Tried a lot of solutions here on stackoverflow already but i just can't get it working. Would love to have some custom made help for my situation and hopefully help others.
Without SSL the situation is like this:
On my node.js script
var app = require('http').createServer(); var io = require('socket.io')(app); app.listen(8080);
In my html page
var socket = io('http://mywebsite.com:8080');
This is working fine but when i throw a SSL certificate in the mix it goes wrong. I tried some solutions like below:
var https = require('https'), fs = require('fs'); var options = { key: fs.readFileSync('/server.key'), cert: fs.readFileSync('/server.crt') }; var app = https.createServer(options); var io = require('socket.io').listen(app); app.listen(8080);
var io = io('https://mywebsite.com', { secure: true });
Any suggestion is appreciated!
Your code var io = require('socket.io').listen(app);
is not correct. It should be var io = require('socket.io')(app);
since the require from socket io gives back a function (and you need to pass the server into it).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.