Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

NodeJS - SocketIO over SSL with websocket transport

NodeJS - SocketIO over SSL with websocket transport


I have a NodeJS-socketIO server that has clients listening from JS, PHP & Python. It works like a charm when the communication happens over plain HTTP/WS channel.

Now, when i try to secure this communication, the Websocket Transport is not working anymore. It falls back to xhr-polling(long polling) transport. Xhr-polling still works for JS client but not on python which purely depends on socket transport.

Things i tried:

  1. On node, Using https(with commercial certificates) instead of http - Works good for serving pages via Node but not for socketIO
  2. Proxy via HAProxy (1.15-dev19). From HTTPS(HAProxy) to HTTP(Node). Couldn't get Websocket transport working and it falls back to xhr-polling on JS. Python gets 502 on handshake.
  3. Proxy via STunnel (for HTTPS) -> HAProxy(Websocket Proxy) -> Node(SocketIO) - This doesnt work either. Python client still gets 502 on handshake.
  4. Proxy via Stunnel(HTTPS) -> Node(SocketIO) - This doesnt work too. Not sure if STunnel support websocket proxy
  5. node-http-proxy : Throws 500(An error has occurred: {"code":"ECONNRESET"}) on websocket and falls back to xhr-polling

Im sure its a common use case and there is a solution exist. Would really appreciate any help.

Thanks in advance!

Problem courtesy of: Karthik Jayapal


My case seems to be a rare one. I built this whole environment on a EC2 instance based on Amazon Linux. As almost all the yum packages are not up to date, i had to install pretty much every yum packages from source. By doing so i could have missed configuration unchanged/added. Or HAProxy required lib could have been not the latest.

In any case, i tried building the environment again on ubuntu 12.04 based EC2 instance. HAProxy worked like a charm with a bit of configuration tweaks. I can now connect my SocketIO server from JS, Python & PHP over SSL without any problem. I could also create a Secured TCP Amazon ELB that listens on 443 and proxy it to non-standard port (8xxx).

Let me know if anyone else encounters a similar problem, I will be happy to help!

Solution courtesy of: Karthik Jayapal


View additional discussion.

This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

NodeJS - SocketIO over SSL with websocket transport


Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription