如何编写安全套接字IO客户端

时间:2015-12-13 11:19:23

标签: node.js socket.io client

是否有任何关于如何编写socket.io客户端的文档或示例,该客户端安全地连接到socket.io服务器(加密连接,而不仅仅是plain-text token authentication)?

以下代码显示了我如何创建服务器,我可以测试服务器正在使用" 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

提前谢谢你:)

0 个答案:

没有答案