0
votes

i use ratchet to create chat. but i want to send message from controller to specific user. how i can access to $connections to find the user and sent the message

public function onOpen(ConnectionInterface $conn)
    {
        $this->connections[] = $conn;
    }

i run server like this

$server = IoServer::factory(new HttpServer(
            new WsServer(
                new Notification($this->getContainer())
            )
        ), 8080);

        $server->run();
1

1 Answers

0
votes

The best solution would probably be to use the SessionProvider: http://socketo.me/docs/sessions

There are also simpler solutions, like using the connection id or a name for each connection.

Also, here's a great article on Ratchet with Symfony: https://medium.com/@nihon_rafy/create-a-websocket-server-with-symfony-and-ratchet-973a59e2df94