L
L
LightSid2016-12-22 23:26:00
Node.js
LightSid, 2016-12-22 23:26:00

How to send a socket message over https?

Hello, I have a domain and vps that hosts the site.
The domain is directed to the cloudflare servers, and there it is connected to the VPS IP.
When using Cloudflare, the site can work over https.
The site has a real-time online counter, data is transmitted via socket.io.
And everything works fine via http, but if you go via https, then the site tries to get data via https, which is not configured on the server and it is not needed there! That is, https online is not displayed
Please tell me how to solve this problem.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Fet, 2016-12-30
@halenharper

Raise via https.

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);
});

Only in this case you need to have certificate files

A
Alexey Cheremisin, 2017-05-19
@leahch

Wow, use ByteBuffer from Java NIO, it will be nice! There are just the right methods like getInt / Float, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question