how to get session id of socket.io client in Client

后端 未结 8 873
谎友^
谎友^ 2020-12-07 15:44

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,          


        
8条回答
  •  -上瘾入骨i
    2020-12-07 16:15

    For some reason

    socket.on('connect', function() {
        console.log(socket.io.engine.id);
    }); 
    

    did not work for me. However

    socket.on('connect', function() {
        console.log(io().id);
    }); 
    

    did work for me. Hopefully this is helpful for people who also had issues with getting the id. I use Socket IO >= 1.0, by the way.

提交回复
热议问题