Answer the question
In order to leave comments, you need to log in
How to make WebSockets work on HTTPS?
I recently switched the server to HTTPS, after the transition WebSockets stopped working.
The protocol has been changed from ws to wss on the client. On the server (running on NODE JS), certificate files were also connected and the necessary settings were made. As a result, now an error is thrown on clients:
WebSocket connection to ' wss://XXX.XX.XXX.XXX:4433/ ' failed: WebSocket opening handshake was canceled
var https = require('https');
var WebSocketServer = require('ws'), fs = require('fs');
var port = 4433;
var app = null;
var processRequest = function( req, res ) {
res.writeHead(200);
res.end("All glory to WebSockets!\n");
};
app = https.createServer({
key: fs.readFileSync('/etc/nginx/ssl/server.key'),
cert: fs.readFileSync('/etc/nginx/ssl/bundle.crt'),
requestCert: true,
rejectUnauthorized: false,
}, processRequest ).listen(port);
var webSocketServer = new WebSocketServer.Server( { server: app } );
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question