0

I got the code:

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

thinking that I can load socket.io from the client via

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

but I get the error

SSL connection error

It all works fine for http and port 80. What do I need to do to get it working for serving from HTTPS?

KKK
  • 1,085
  • 11
  • 33
  • Duplicate: http://stackoverflow.com/questions/6599470/node-js-socket-io-with-ssl – BorisOkunskiy Aug 07 '13 at 16:33
  • Perhaps not an exact duplicate, but if you follow the steps in the question @incarnate referenced (including loading your ssl certs) you should be able to get it up and running. – dc5 Aug 07 '13 at 17:34

1 Answers1

0

UPDATE:

I have managed to update the code, here to share with the community:I now get the socket.io.js served to the client but I cant get the subscription to REDIS channels working quite yet.

So here is the latest code:

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);
});

Oh, by the way, don't forget to connect to Redis in your rails app with:

REDIS = Redis.new(:host => 'localhost', :port => 6800, :password=>"mySecretPasswqord")
KKK
  • 1,085
  • 11
  • 33