Skip to content Skip to sidebar Skip to footer

Not Able Emit Message After Adding Ssl Over Socket.io

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, n

Solution 1:

I always leave the ssl burden to stunnel, an ssl proxy that listens on a secure port defined by you (such as 443) and forwards all incoming traffic, already decrypted, to another port where your non-ssl application is listening (usually 80).

Here you have a gist with a simple stunnel configuration: https://gist.github.com/mbenedettini/5911415

Solution 2:

I solved the problem after a few days.

The problem was in the following line on the client side.

var socket = io.connect("https://xyz.com:8888", {secure : true} );

We are not supposed to add {secure : true}, so the line simply becomes

var socket = io.connect("https://xyz.com:8888" );

How I came to know about this solution? I learnt how to analyse the Web Socket data traffic using Chrome Dev tools

Very soon I found out that the client was emitting {secure : true} as the 1st element of the array. This changed the structure of the entire object. As a result of all this server was not able to resolve the Event Name, since the first array element was not containing the event name.

I removed {secure : true} and it worked. :)

Post a Comment for "Not Able Emit Message After Adding Ssl Over Socket.io"