P
P
Painkiller_132017-12-07 13:39:10
Node.js
Painkiller_13, 2017-12-07 13:39:10

Nodejs + Socket.io + https?

Created certificates via let's encrypt.
Got the files. Connected via nginx privkey.key fullchain.pem.
The domain has successfully started working on https and writes that it is protected.

But connecting the same certificates to the application. The client, when accepting them, rejects them with an error.
net::ERR_CONNECTION_CLOSED

Server-side code.

var fs = require('fs');

var options = {
  key: fs.readFileSync('ssl/privkey.pem'),
  cert: fs.readFileSync('ssl/fullchain.pem')
};

var httpServer = require('http').createServer();
var httpsServer = require('https').createServer(options);
var ioServer = require('socket.io');

var io = new ioServer();
io.attach(httpServer);
io.attach(httpsServer);
httpServer.listen(7165);
httpsServer.listen(7166);

io.sockets.on('connection', function (socket){});


From the client side
var port = location.protocol === 'https:' ? 7166 : 7165;
var socketIO = io(0.0.0.0:'+port);

socketIO.once('connect', function(){});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Korobkov, 2017-12-07
@Painkiller_13

But connecting the same certificates to the application. The client, when accepting them, rejects them with an error.

Because the certificates are issued for a specific domain. This domain should be specified in
var socketIO = io('0.0.0.0:'+port);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question