Socket IO | How to get the client transport type on the serverside?

后端 未结 7 742
梦谈多话
梦谈多话 2021-01-01 23:51

I need to know what transport method a client is using for some conditional statements on the nodeJS serverside.

Does anyone know how I can get that

7条回答
  •  借酒劲吻你
    2021-01-02 00:01

    As of Socket.IO 1.0:

    Client:

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

    Server:

    io.sockets.on('connection', function(socket) {
        console.log(socket.conn.transport.name);
    }
    

提交回复
热议问题