是否有任何关于如何编写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
提前谢谢你:)