我收到了代码:
var io = require('socket.io').listen(443);
var redis = require('redis');
认为我可以通过
从客户端加载socket.iohttps://<MY IP>/socket.io/socket.io.js
但我收到了错误
SSL connection error
这一切都适用于http和端口80.我需要做些什么来使其能够通过HTTPS提供服务?
答案 0 :(得分:0)
更新:
我已经设法更新代码,在这里与社区分享:我现在将socket.io.js提供给客户端,但我无法获得REDIS频道的订阅工作。
所以这是最新的代码:
var https = require('https');
var fs = require('fs');
var socketio = require('socket.io');
var redis = require('redis');
var nClients=0;
var nPort = 6800; // Port of the Redis Server
var nHost = "123.123.123.123"; // Host that is running the Redis Server
var sPass = "mySecretPassword";
var svrPort = 443; // This is the port of service
var svrOptions = {
key: fs.readFileSync('/etc/ssl/private/my.key'),
cert: fs.readFileSync('/etc/ssl/private/my.crt'),
ca: fs.readFileSync( '/etc/ssl/private/cabundle.crt')
};
var servidor = https.createServer( svrOptions , function( req , res ){
res.writeHead(200);
res.end('OK');
});
io = socketio.listen( servidor );
// Now listen in the specified Port
servidor.listen( svrPort );
cli_sub = redis.createClient(nPort,nHost);
cli_sub.auth(sPass, function() {console.log("Connected!");});
cli_sub.subscribe("mychannel");
cli_sub.on("message",function(channel,message) {
console.log("Incoming Message");
console.log(message);
io.sockets.emit('STATSOUT', message);
});
哦,顺便说一句,不要忘记使用以下链接连接到rails应用程序中的Redis:
REDIS = Redis.new(:host => 'localhost', :port => 6800, :password=>"mySecretPasswqord")