WebSocket with SSL

Eric picture Eric · Mar 16, 2012 · Viewed 127.8k times · Source

Is it possible to have WebSockets with HTTPS?

When switching to HTTPS, my WebSocket returns a security error and works perfectly with regular HTTP.

Below, a snippet;

socket = new WebSocket("ws://my_www:1235"); 

Answer

Peter Moskovits picture Peter Moskovits · Mar 17, 2012

The WebSocket connection starts its life with an HTTP or HTTPS handshake. When the page is accessed through HTTP, you can use WS or WSS (WebSocket secure: WS over TLS) . However, when your page is loaded through HTTPS, you can only use WSS - browsers don't allow to "downgrade" security.