send data from server to clients with zeroMQ 
I've got a simple task I want to achieve. I want to send messages to client connections from server side when something happens on the server. 

I do not want to just send messages in response to clients sending messages to the server as in the example of the Chat app. 
To do that zeroMQ seems to be the way to go. The trigger to sending messages comes from another php file which is called internally by my server side code via simple curl.

trigger php file test2.php:

```php
$context = new ZMQContext(1);
$req = new ZMQSocket($context, ZMQ::SOCKET_REQ);
$req->connect("tcp://127.0.0.1:5555");
$req->send("send from test2.php \n");
```

And this is the responder test1.php:

```php
$context = new ZMQContext(1);
$responder = new ZMQSocket($context, ZMQ::SOCKET_REP);
$responder->bind("tcp://127.0.0.1:5555");
while (true) {
    $request = $responder->recv();
    // Oooh you want me to send messages to clients? I'll do that!
    //just here to keep zeromq happy
    $responder->send($request. " World");
}
```


Take Chat and chat-server example from the ratchet tutorial. It looks nearly identical to this

chat-server.php
```php
use Ratchet\Http\OriginCheck;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use Ratchet\Server\IoServer;
use MyApp\Chat;

    require getcwd().'/vendor/autoload.php';
    $checkedApp = new OriginCheck(new WsServer(new Chat()), array('localhost'));
    $checkedApp->allowedOrigins[] = 'mydomain.com';

$server = IoServer::factory(
	new HttpServer($checkedApp),
	8080
);
$server->run();
```


and Chat.php

```php
<?php
namespace MyApp;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;

class Chat implements MessageComponentInterface {
    protected $clients;
    public function __construct() {
        $this->clients = new \SplObjectStorage;
    }

    public function onOpen(ConnectionInterface $conn) {//trimmed for clarity  }
    public function onMessage(ConnectionInterface $from, $msg) {
        $numRecv = count($this->clients) - 1;
        echo sprintf('Connection %d sending message "%s" to %d other connection%s' . "\n"
            , $from->resourceId, $msg, $numRecv, $numRecv == 1 ? '' : 's');

        foreach ($this->clients as $client) {
            if ($from !== $client) {
                $client->send($msg);
            }
        }
    }

    public function onClose(ConnectionInterface $conn) {//trimmed for clarity }
    public function onError(ConnectionInterface $conn, \Exception $e) {//trimmed for clarity }
}
```




All I want to be able to do is to call

`$oneOfTheClientConnections->send($msg);`

in **responder test1.php**
Sound extremely easy on paper, but I've spent days figuring out how to d this. Could you help me out? What should I do with chat-server.php or Chat.php so that zeroMQ will be able to trigger sending messages?

The solution to problem is given by the author of Ratchet himself at https://www.youtube.com/watch?v=04jVCKLXttk&t=45m , but the code has lots of gaps I need to fill in.

This is the new code:

```php
<?php
// include "Chat.php";
use Ratchet\Http\OriginCheck;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use Ratchet\Server\IoServer;
use MyApp\Chat;

require getcwd().'/vendor/autoload.php';
$checkedApp = new OriginCheck(new WsServer(new Chat()), array('localhost'));
$checkedApp->allowedOrigins[] = 'mydomain.com';

$server = IoServer::factory(
    new HttpServer($checkedApp),
    8080
);

$context = new React\ZMQ\Context($server);
$responder = new ZMQSocket($context, ZMQ::SOCKET_REP);
$responder->bind("tcp://127.0.0.1:5555");
$responder->on("message", array($checkedApp,"injMethod"));

$server->run();
```

But unfortunately I am getting an error:

**React\ZMQ\Context::__construct() must implement interface React\EventLoop\LoopInterface, instance of Ratchet\Server\IoServer given**

That is strange, because `IoServer` implements LoopInterface.

