-1

currently I use

let connectTo = "http://myip:myport";
var socket = io.connect(connectTo, {secure: true});

on client side, and

const port = myport;
const io = require('socket.io')(port);

on server side, I want to use https:// instead of http://, how do I do that? I also heard I need a certificate thing, how do I get that? and how to set it up? cause stupid anti viruses think the socket.io is "dangerous" when it isnt.. (the client side is on my electron application)

Richieboi
  • 13
  • 2
  • Have you tried this? https://stackoverflow.com/questions/6599470/node-js-socket-io-with-ssl To get ssl sertificate use https://letsencrypt.org/getting-started/ – artanik Feb 16 '20 at 00:25
  • This seems far too broad, can you focus on a single issue? – AMC Feb 16 '20 at 00:54

1 Answers1

1

You create your own https server (with appropriate certificates) and then bind socket.io to that server. Every socket.io connection starts with an http(s) request so that's why you need that kind of server.

const https = require('https');

const options = {
  key: fs.readFileSync('somePath/agent2-key.pem'),
  cert: fs.readFileSync('somePath/agent2-cert.pem')
};
const server = https.createServer(options);
const io = require('socket.io')(server);
server.listen(443);

I also heard I need a certification thing, how to I get that?

There are lots and lots of sources. You can start here: https://letsencrypt.org/. You will have to bind a certificate to a particular domain as that's part of the security that it delivers.


Then, in the client, you would connect using an https URL such as:

const socket = io('https://example.com');
jfriend00
  • 683,504
  • 96
  • 985
  • 979
  • I also do not have a domain so its a IP like `12.23.2.3.2` (example), how do I get https with certificate on that? – Richieboi Feb 16 '20 at 19:34
  • @Richieboi - See https://stackoverflow.com/questions/2043617/is-it-possible-to-have-ssl-certificate-for-ip-address-not-domain-name. – jfriend00 Feb 16 '20 at 21:44