You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is it possible to receive extra information from the client ?
For example :
$socket->on('add user', function ($username) use($socket){
global $usernames, $numUsers;
// we store the username in the socket session for this client
$socket->username = $username;
// add the client's username to the global list
$usernames[$username] = $username;
++$numUsers;
$socket->addedUser = true;
$socket->emit('login', array(
'numUsers' => $numUsers
));
// echo globally (all clients) that a person has connected
$socket->broadcast->emit('user joined', array(
'username' => $socket->username . ' and extra information is : ' . $socket->extra,
'numUsers' => $numUsers
));
});
How to send and recive $socket->extra ?
The text was updated successfully, but these errors were encountered:
Yes you can, for example transtransmission extra information of age.
Javascript side.
socket.emit('add user',{name: 'tom',age: 13});
Server side.
$socket->on('add user', function ($user_info) use($socket){
global$usernames, $numUsers;
// we store the username in the socket session for this client$username = $user_info['name'];
$socket->username = $username;
// =====Here get age form client======$age = $user_info['age'];
// add the client's username to the global list$usernames[$username] = $username;
++$numUsers;
$socket->addedUser = true;
$socket->emit('login', array(
'numUsers' => $numUsers
));
// echo globally (all clients) that a person has connected$socket->broadcast->emit('user joined', array(
'username' => $socket->username,
'numUsers' => $numUsers,
'age' => $age, // ====== extra information of age =====
));
});
Is it possible to receive extra information from the client ?
For example :
How to send and recive $socket->extra ?
The text was updated successfully, but these errors were encountered: