2

Is there any documentation or example on how to write a socket.io client that connects to a socket.io server securely (encrypted connection, not just plain-text token authentication)?

The following code shows how I create the server, I can test that the server is up using "curl --cacert ssl_cert.pem https://localhost":

// declarations
var fs = require('fs');
var io;
var app;
var httpsServ = require('https');
var host = "localhost";
var port = 443;

var processRequest = function (req, res) {
    // empty method
}

// create httpsServ 
app = httpsServ.createServer({

    // server SSL key/cert files
    key: fs.readFileSync("ssl_key.pem"),
    cert: fs.readFileSync("ssl_cert.pem")

}, processRequest).listen(port);

// create io socket server
io = require('socket.io').listen(app, function () {
        console.log("Server started and running " + host + ":" + port);
    });

// implement request/response
io.sockets.on('connection', function (socket) {

        socket.on("ClientRequest", function (data) {
            // handle client request
        });

    });

// ...etc

Thank you in advance :)

Community
  • 1
  • 1
Haitham Sweilem
  • 1,633
  • 1
  • 12
  • 13
  • What is your question? It appears as if you have just written a Socket.IO server that connects over SSL. – Gary Dec 13 '15 at 16:04
  • The question is in the first two lines ;) how can I write a client that connects securely to this server? – Haitham Sweilem Dec 13 '15 at 20:47
  • As far as I know, it's possible to initiate a client-side Socket.IO connection with both `https` and `wss` protocols by using one of them in your `.connect` call. This may not be what you're after, though- not sure I understood your question, myself. – Connor Dec 13 '15 at 22:07
  • @Connor thanks, this is exactly what I want to do, how can I create this (https/wss) connection? – Haitham Sweilem Dec 14 '15 at 04:32
  • This answer to a similar question ought to point you in the right direction: http://stackoverflow.com/a/6601067 Currently on my phone or I'd try to answer more specifically. – Connor Dec 14 '15 at 13:00

0 Answers0