2013-12-17 11 views

risposta

13

Si può provare questo

io.sockets.on('connection', function (socket) { 
    socket.on('event_name', function(data) { 
     // you can try one of these three options 

     // this is used to send to all connecting sockets 
     io.sockets.emit('eventToClient', { id: userid, name: username }); 
     // this is used to send to all connecting sockets except the sending one 
     socket.broadcast.emit('eventToClient',{ id: userid, name: username }); 
     // this is used to the sending one 
     socket.emit('eventToClient',{ id: userid, name: username }); 
    } 
} 

e sul client

socket.on('eventToClient',function(data) { 
    // do something with data 
     var id = data.id 
     var name = data.username 

}); 
5

provare a inviare l'oggetto complessivamente:

$('form').submit(function(){  
var loginDetails={ 
    userid : userid, 
    username : username 
    }; 
client.emit('sentMsg',loginDetails); 
} 
Problemi correlati