WSS + Fixes in threads examples

Hi

I've added wss support and fixed multi-threading example (it didn't work before)

And I've refactored a bit websocket (can remove if you think if that bad thing)