Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save Data on Socket in Socket.IO

I want to save some data on the socket, server side, so whenever the client emits any data to the server, I want that data to be available!

One use case can be storing a token on the socket. When the client is connecting for the first time, it will emit the token, if it has one, or it will show the login page and then the login data will be sent to the server. Whichever one it is, I want to store the token on the server, so that every request after that doesn't need to specify the token.

Later, I'll use RedisStore, so all the data will be accessible all the servers running the app.

My only question is, where do I store the data on the socket so it's associated with that client?

like image 759
Arjun Bajaj Avatar asked Apr 08 '13 10:04

Arjun Bajaj


1 Answers

on http://socket.io/#how-to-use scroll to: Storing data associated to a client

use socket.set and socket.get to set and get data asynchronously

like image 51
frederik-b Avatar answered Oct 21 '22 06:10

frederik-b