socket.io and cookies

1,984 views
Skip to first unread message

metamind

unread,
Aug 11, 2011, 7:36:52 AM8/11/11
to nodejs
Hi,

Just looking at this: (http://stackoverflow.com/questions/4311180/how-
to-send-cookies-when-connecting-to-socket-io-via-websockets) which
says that cookies can't be sent on connection.

Would it be difficult to add a parameter to the connect function so we
could use something like this:

var socket = io.connect('http://server:port', {token: token});

The second parameter could be be passed straight up to the server.

Just a thought.

Cheers.

Arnout Kazemier

unread,
Aug 11, 2011, 7:48:36 AM8/11/11
to nod...@googlegroups.com
That is a old topic, that is based on Socket.IO 0.6 where we indeed, didn't have support for cookies. (there are various of reasons why we could not implement that in 0.6 but that is out of the scope of this question :))

Anyways in 0.7 we introduced the `handshake` property, this property contains all data that we gathered during the initial handshaking with the server (stuff as headers, and ip etc is stored). You can read more about it here: https://github.com/LearnBoost/socket.io/wiki/Authorizing

As for sending params to the server, in 0.7.8 we added support for query strings in the connection url. So you can do:

io.connect('http://localhost:8080?pewpew=pew');

and you can than read it out during authorization and in handshake;

var io = require(socket.io).listen(8080)

io.sockets.on(connection, function (socket) {
.. bla bla

console.log(socket.handshake.query.pewpew) // => pew

});

> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en

metamind

unread,
Aug 11, 2011, 7:59:19 AM8/11/11
to nodejs
cool. thanks Arnout.

Ken Whitesell

unread,
Sep 4, 2011, 1:34:16 PM9/4/11
to nod...@googlegroups.com
Arnout Kazemier <info@...> writes:

> As for sending params to the server, in 0.7.8 we added support for query
strings in the connection url. So you
> can do:
>
> io.connect('http://localhost:8080?pewpew=pew');
>
> and you can than read it out during authorization and in handshake;
>

I've got that working, but it appears to me that those query strings are sent in
every subsequent get. (long-polling)

I'm sending ~ 200 characters for my initial authorization (granted, I could
probably cut that in half) and I'm seeing it on every request after that. Is
there a way to change / remove those parameters after the handshake has finished?


Reply all
Reply to author
Forward
0 new messages