How to figure out this problem please ?
My question is related to sockets, you have to own some knowledge on it in order to answer please.
I am trying to save socket.id
on a variable declared outside of the function itself, but without success ... used even array but same thing.
Here is my code:
var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http)
app.use('/', express.static('www'));
http.listen(3000, function(){
console.log('listening on *:3000');
});
var token_user = {};
io.on('connection', function(socket){
token_user["something"] = socket.handshake['query']['something'];
token_user["socket_id"] = socket.id;
});
console.log(token_user["socket_id"]); // Undefined
I got a message as it's: UNDEFINED
.
Any solution or other way to get socket.id
outside of there please in order to use it in other function ?