Socket.io and Session Data

Is this a suitable way to store my temporary application data?

socket.on('connection', function(client){ client.myappsdata = { a: true, b: false } } 
+6
source share
1 answer

I prefer something a little heavier.

Pseudo Code:

 // ClientManager.js var Manager = new function() { this._clients = []; this.set = function(client, data) { this._clients[client.sessionId] = data; }; this.get = function(client) { return this._clients[client.sessionId]; } }; module.exports = function() { return Object.create(Manager); }; // main.js var manager = require("ClientManager")(); /* ... */ socket.on("connection", function(client) { manager.set(client, { /* ... */ }); } 

Basically, each client has a sessionId , so store your data in a hash entered using this sessionId

+9
source

Source: https://habr.com/ru/post/889721/


All Articles