I had built an application using Node JS and socket.io. It was working fine. Since I had to move the application over a secure connection, I changed the code to support SSL.
But, now I am unable to do a socket.emit
. Neither server, nor the client is able to emit the messages.
The connections are made successfully, but nothing gets emitted afterwards.
Here is the code.
Server Side
var fs = require( 'fs' );
var options = {
key: fs.readFileSync('/etc/httpd/conf.d/ssl/*.xyz.in.key'),
cert: fs.readFileSync('/etc/httpd/conf.d/ssl/xyz.in.crt'),
requestCert: true,
rejectUnauthorized: false // Tried both, with and without this line.
};
var io = require( 'socket.io' ).listen( 8888, options );
io.sockets.on('connection', OnConnection );
io.set("origins", "*:*"); // Tried with and without this line.
// Called when a connection is made with a new Client.
function OnConnection ( socket )
{
console.log( socket.id + " connected" ); // This line gets printed.
socket.on('ev_SendMsgForApproval', OnMsgReceivedForModApproval );
}
function OnMsgReceivedForModApproval( data )
{
console.log( data ); //This does not get executed. :(
}
Client Side
var socket = io.connect("https://xyz.com:8888", {secure : true} );
// This message get called for sure.
function OnMsgSendClick()
{
console.log( "Hi" ); // This gets printed on browser's console.
socket.emit( 'ev_SendMsgForApproval', { chatMsg: "Hi" } );
return false;
}
I have also tried to do emit from server, but that data, does not reach the client either. In debug I am able to see that server has emitted something, but that does not reach the client.
All this was working fine without the SSL.
What could be the issue? Stuck with this from a long time. Please help.