question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

read cookies setted after socket.io connection

See original GitHub issue

Maybe is a stupid question but if i set or update a cookie after client connection i can’t get the new values using socket.request.headers.cookie server side without page refresh.

Client side socket = io(); document.cookie="foo=bar"; socket.emit('this', { is: 'test'});

Server side io.sockets.on('connection', function (socket) { socket.on('this', function(reqData){ console.log(socket.handshake.headers); // there is no cookies here! }); }

If i update an access token cookie using ajax i need to read the updated cookie server side without page refresh but it seems that sochet.io set the cookies only during handshake.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
krishnaTORQUEcommented, Mar 11, 2021

@elbasan I guess NO web socket make connection through P2P so yes there are some issue for session & cookie.

1reaction
darrachequesnecommented, Feb 18, 2021

For future readers: the handshake object indeed contains the headers of the first HTTP requests of the Socket.IO session.

Documentation: https://socket.io/docs/v3/server-socket-instance/#Socket-handshake

You can force the reconnection on the client-side:

if (socket.io.engine) { socket.io.engine.close(); }
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to deal with cookies - Socket.IO
When using the cookie option, the server will send a cookie upon handshake (the first HTTP request of the session), with the value...
Read more >
node.js socket.io get cookie value - Stack Overflow
You can use the cookie module to do this. var cookie = require("cookie") //installed from npm; io. on('connection', function (socket) { var cookief...
Read more >
Create a Secure Chat Application with Socket.IO and React
This tutorial shows you how to create a real-time chat application using JavaScript and Socket.IO.
Read more >
Everything you need to know about Socket.IO - Ably Realtime
As we have explored, Socket.IO is a great tool for developers wanting to set up bi-directional socket connections between client and server.
Read more >
How to manage users in socket.io in Node.js ? - GeeksforGeeks
js and express. Create two folders in your main directory name server(backend) and client(frontend). Socket.on will be an event that will be ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found