title: Sending messages from PHP script to multiple Ratchet Websocket apps (via ZMQ Socket)
body: <p>So, I am running a Ratchet (php) websocket server with multiple routes that connect do multiple Ratchet apps (MessageComponentInterfaces):</p>
  
  <pre><code>//loop 
  $loop   = \React\EventLoop\Factory::create();
  
  //websocket app
  $app = new Ratchet\App('ws://www.websocketserver.com', 8080, '0.0.0.0', $loop);
  
  /*
   * load routes
   */
  $routeOne = '/example/route';
  $routeOneApp = new RouteOneApp();
  $app-&gt;route($routeOne, $routeOneApp, array('*'));
  
  $routeTwo = '/another/route';
  $routeTwoApp = new AnotherApp();
  $app-&gt;route($routeTwo, $routeTwoApp, array('*'));
  </code></pre>
  
  <p>From here I am binding a ZMQ socket, in order to be able to receive messages sent from php scripts run on the normal apache server. </p>
  
  <pre><code>// Listen for the web server to make a ZeroMQ push after an ajax request
  $context = new \React\ZMQ\Context($loop);
  $pull = $context-&gt;getSocket(\ZMQ::SOCKET_PULL);
  $pull-&gt;bind('tcp://127.0.0.1:5050'); // Binding to 127.0.0.1 means the only client that can connect is itself
  $pull-&gt;on('message', array($routeOneApp, 'onServerMessage'));
  </code></pre>
  
  <p>Finally, the server is started:</p>
  
  <pre><code>//run
  $loop-&gt;run();
  </code></pre>
  
  <p>This works perfectly fine as long as i am binding only one of the ratchet apps to the ZMQ socket. However, i would like to be able to separately push messages to both of the Ratchet apps. For this purpose i thought of binding two ZMQ sockets to different routes like:</p>
  
  <pre><code>$pullOne-&gt;bind('tcp://127.0.0.1:5050' . $routeOne); // Binding to 127.0.0.1 means the only client that can connect is itself
  $pullOne-&gt;on('message', array($routeOneApp, 'onServerMessage'));
  </code></pre>
  
  <p>and</p>
  
  <pre><code>$pullTwo-&gt;bind('tcp://127.0.0.1:5050' . $routeTwo); // Binding to 127.0.0.1 means the only client that can connect is itself
  $pullTwo-&gt;on('message', array($routeTwoApp, 'onServerMessage'));
  </code></pre>
  
  <p>However, this leads to an error message from ZMQ when binding the second socket, saying the given address is already in use.</p>
  
  <p>So the question is, is there any other way to use routes over a ZMQ socket? 
  Or should i use other means to distinguish between messages for the separate Ratchet apps, and if so, what would be a good solution? 
  I thought about binding to 2 different ports, but figured that would be a pretty ugly solution?!</p>