2013-08-07 102 views
0

服務socket.io我的代碼:通過https

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

以爲我可以從客戶端通過

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

加載socket.io,但我得到的錯誤

SSL connection error 

對於http和端口80,這一切都正常工作。我需要做些什麼才能使它從HTTPS服務?

+0

重複:HTTP:// stackoverflow.com/questions/6599470/node-js-socket-io-with-ssl – incarnate

+0

也許不是一個確切的重複,但如果你按照問題中的步驟@incarnate引用(包括加載你的ssl證書),你應該能夠啓動並運行。 – dc5

回答

0

UPDATE:

我已成功地更新代碼,在這裏與社會各界分享:我現在明白了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); 
}); 

哦,對了,別忘了與應用程序連接到的Redis在你的軌道:

REDIS = Redis.new(:host => 'localhost', :port => 6800, :password=>"mySecretPasswqord")