Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I access a cookie from Socket.io?

I want to set some user information in a cookie and be able to access it on connection, is this possible?

like image 841
Dan Avatar asked Jan 21 '11 00:01

Dan


People also ask

How do I send cookies from server to client?

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.

Should I use Socket.IO or WebSockets?

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.

How do you set cookies on a WebSocket?

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.

How much traffic can Socket.IO handle?

Once you reboot your machine, you will now be able to happily go to 55k concurrent connections (per incoming IP).


1 Answers

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

like image 117
gabrtv Avatar answered Oct 04 '22 11:10

gabrtv