PHP WebSocket ZMQ - Chat Operation - Send data to specific user
You are using Ratchet
on backend side, right?
So, here you have very good example of case you need:
http://socketo.me/docs/hello-world
You should keep your client connections inside $clients
property (not collection of resources id!). So, you can choose one element from this collection and send a message only to this client.
Example:
public function onSubscribe(ConnectionInterface $conn, $topic) { // When a visitor subscribes to a topic link the Topic object in a lookup array $subject = $topic->getId(); $ip = $conn->remoteAddress; if (!array_key_exists($subject, $this->subscribedTopics)) { $this->subscribedTopics[$subject] = $topic; } $this->clients[] = $conn; // you add connection to the collection $conn->send("Hello new user!"); // you send a message only to this one user}