I want to get session id of client in my socket.io client.
here is my socket.io client :
var socket = new io.Socket(config.host, {port: config.port, rememberTransport: false}); // when connected, clear out display socket.on('connect',function() { console.log('dummy user connected'); }); socket.on('disconnect',function() { console.log('disconnected'); }); socket.connect(); return socket;
I want to get session id of this client , how can i get that ?
You can check the socket. connected property: var socket = io. connect(); console.
var socket = require('socket. io-client')('ws://ws.website.com/socket.io/?EIO=3&transport=websocket'); socket. on('connect', function() { console. log("Successfully connected!"); });
Use Monitor.io to observe connections and replay messages It shows a list of active Socket.io client connections for your application. You can use the monitoring interface to broadcast messages–either globally or to a specific client.
Have a look at my primer on exactly this topic.
UPDATE:
var sio = require('socket.io'), app = require('express').createServer(); app.listen(8080); sio = sio.listen(app); sio.on('connection', function (client) { console.log('client connected'); // send the clients id to the client itself. client.send(client.id); client.on('disconnect', function () { console.log('client disconnected'); }); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With