Ratchet: How to send private message for user?

Created on 27 Nov 2014  路  2Comments  路  Source: ratchetphp/Ratchet

I have chat everything is ok. But now my server send message for all users. I want to send private message. How can i identify each user and send private message ?
Client is iOS.
example
Client send to server json data
{
userID:444,
sendTo:555,
message:"Hello"
}
sorry for my poor English..

question

Most helpful comment

insert this on onMessange event func

$json =  (json_decode($msg,true)); // {"userID":"#", "sendTo":"#", "message":"lorem"}
$msg = $json['message'];
$tosendid = $json['sendTo'];
foreach ($this->clients as $client) {
   if ($tosendid == $client->resourceId) {
                $client->send($msg);
   }
}

All 2 comments

insert this on onMessange event func

$json =  (json_decode($msg,true)); // {"userID":"#", "sendTo":"#", "message":"lorem"}
$msg = $json['message'];
$tosendid = $json['sendTo'];
foreach ($this->clients as $client) {
   if ($tosendid == $client->resourceId) {
                $client->send($msg);
   }
}

I have the same situation and I don't understand how to get $client->resourceId on the front (browser)? I mean when I send message I need to know to which user send this message. In example above you compare $client->resourceId. How I can get it?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dschissler picture dschissler  路  3Comments

lubatti picture lubatti  路  6Comments

ThePatzen picture ThePatzen  路  3Comments

tasaif picture tasaif  路  6Comments

Opice picture Opice  路  4Comments