10
私はclientidとユーザー名を持っていて、両方ともソケットで送信します。 Socket.ioを使用して1つのメッセージで2つの変数を送信するにはどうすればよいですか?
client.userid = userid;
client.username = username;
client.emit('onconnected', { id: client.userid, name: client.username });
iは、例えば、これを試してみましたが、あなたがこの
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 });
}
}
を試すことができます