I
I
InsUpCray2015-10-28 19:27:01
Node.js
InsUpCray, 2015-10-28 19:27:01

How to connect a certificate to socket io?

Hello dear users. I have a question, how to connect ssl certificates with socket io?
Here's the torn code - this is how the server is configured:
var io = require('socket.io').listen(2095);
var http = require('http');
This is how clients connect:
var socketIO = io(':2095',{'max reconnection attempts':Infinity});
But... When I go through http, everything works for me, but when I write https, it doesn't work, but in the console it says that it can't connect by clicking on the socket request link ( https://domain.pw:2095/socket .io/?EIO=3&transport=... ) gives me something saying "An error occurred while establishing a secure connection". But how to make it secure?
I don't understand any of this!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Aksentiev, 2015-10-28
@Sanasol

procurate through nginx

F
Fet, 2016-12-30
@halenharper

var https = require('https');
var fs = require('fs');
var port = 3001;

var options = {
    key:    fs.readFileSync('www_site_com.key').toString(),
    cert:   fs.readFileSync('www_site_com.crt').toString(),
    ca:     fs.readFileSync('www_site_com.ca-bundle').toString()
};

var app = https.createServer(options);
var io = require('socket.io').listen(app);     //socket.io server listens to https connections

app.listen(port, "0.0.0.0", function() {
    console.log('Listening on Port:' + port);
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question