Ratchet + Symfony3: how to get access to current server from outside

Viewed 234

Here is my Symfony3 command that I'm using for websocket server purpose

    public function __construct(ChatFlowProcessor $chatManager, int $webSocketPort)
    {
        $this->chatManager = $chatManager;
        $this->webSocketPort = $webSocketPort;
        parent::__construct();
    }

    $server = IoServer::factory(
        new HttpServer(
            new WsServer(
                $this->chatManager
            )
        ),
        $this->webSocketPort
    );
    $server->run();

As you see, I've got a chatManager simply using Symfony3 autowiring. The service implements Ratchet MessageComponentInterface.

Now, I want to get access to the server from outside of the connection. I mean, send a message to websocket client using my chatManager, apparently I need to get access to chatManager instance, that stored in WsServer and keep information about all active connections.

Is it possible? Thanks.

1 Answers

You dont need an access to chatManager just to send messages. It's a chat server which only purpose IS to transfer messages from/to all its clients.

Simply create a websocket client, connect it to your server (together other clients) and start sending (and receiving) messages. Any special functionality (e.g. send message to one client only or get list of all clients etc.) must be implemented in chatManager (Ratchets MessageComponentInterface).

Perhaps I misunderstood the question, sorry then.

Related