I want to set some user information in a cookie and be able to access it on connection, is this possible?
To send cookies to the server, you need to add the "Cookie: name=value" header to your request. To send multiple Cookies in one cookie header, you can separate them with semicolons. In this Send Cookies example, we are sending HTTP cookies to the ReqBin echo URL.
First of all, every modern browser supports WebSockets these days. Socket.IO uses much more boilerplate code and resources to make it fall back to other technologies. Most of the time, you don't need this level of support. Even in terms of network traffic, Socket.IO is way more expensive.
You can't set a cookie upon receipt of a webSocket message because it's not an http request. Once the webSocket connection has been established, it's an open TCP socket and the protocol is no longer http, thus there is no built-in way to exchange cookies.
Once you reboot your machine, you will now be able to happily go to 55k concurrent connections (per incoming IP).
Using Socket.IO 0.8.7, you can access request headers via:
socket.handshake.headers
You can find more detail on this at https://github.com/LearnBoost/socket.io/wiki/Authorizing
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With