Send additional data on socket connection

前端 未结 7 455
清酒与你
清酒与你 2020-12-24 10:12

How to best send additional data upon socket connection?

Client:

socket.on(\'connect\',function(){ 
//I\'d like set some values and pass them up to t         


        
相关标签:
7条回答
  • 2020-12-24 11:00

    this is my code on socket version 2.1.1

    //client side
    var socket = io.connect(window.location.origin,{query:'loggeduser=user1'});
    
    // server side
    io.socket.on('connection', function (socket) {
        console.log("loggeduser => " +  socket.handshake.query.loggeduser);
    });
    
    0 讨论(0)
提交回复
热议问题