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

后端 未结 8 884
谎友^
谎友^ 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条回答
  •  一向
    一向 (楼主)
    2020-12-07 16:27

    On Server side

    io.on('connection', socket => {
        console.log(socket.id)
    })
    

    On Client side

    import io from 'socket.io-client';
    
    socket = io.connect('http://localhost:5000');
    socket.on('connect', () => {
        console.log(socket.id, socket.io.engine.id, socket.json.id)
    })
    

    If socket.id, doesn't work, make sure you call it in on('connect') or after the connection.

提交回复
热议问题