0

我得到了代码:

var io = require('socket.io').listen(443);
var redis = require('redis');

认为我可以通过从客户端加载 socket.io

https://<MY IP>/socket.io/socket.io.js

但我得到了错误

SSL connection error

对于 http 和端口 80,一切正常。我需要做些什么才能让它从 HTTPS 服务?

4

1 回答 1

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")
于 2013-08-11T15:09:42.500 回答