0

I have a websocket server written with ratchet and it works well when it is bound to 127.0.0.1:5555. However, i need to run an additional instance of the script on the same machine, so i tried to create another instance bound to a different port, but then clients can connect and subscribe to a topic, yet they don't receive any data that is supposed to be pushed over the connection. I tried many different ports and even different loopbacks (127.0.0.1/8) but the only thing that seems to work is 127.0.0.1:5555. How do i get other ports or loopbacks to work?

Instance #1, which works:

// Listen for the web server to make a ZeroMQ push after an ajax request
$context = new React\ZMQ\Context($loop);
$pull = $context->getSocket(ZMQ::SOCKET_PULL);
$pull->bind('127.0.0.1:5555'); // Binding to 127.0.0.1 means the only client that can connect is itself
$pull->on('message', array($pusher, 'onUpdate'));

// Set up our WebSocket server for clients wanting real-time updates
$webSock = new React\Socket\Server($loop);
$webSock->listen(8080, '0.0.0.0'); // Binding to 0.0.0.0 means remotes can connect
$webServer = new Ratchet\Server\IoServer(
        new Ratchet\Http\HttpServer(
        new Ratchet\WebSocket\WsServer(
        new Ratchet\Wamp\WampServer(
        $pusher
        )
        )
        ), $webSock
);

$loop->run();

Instance #2, bound to another port, which does not work:

// Listen for the web server to make a ZeroMQ push after an ajax request
$context = new React\ZMQ\Context($loop);
$pull = $context->getSocket(ZMQ::SOCKET_PULL);
$pull->bind('127.0.0.1:4444'); // Binding to 127.0.0.1 means the only client that can connect is itself
$pull->on('message', array($pusher, 'onUpdate'));

// Set up our WebSocket server for clients wanting real-time updates
$webSock = new React\Socket\Server($loop);
$webSock->listen(9090, '0.0.0.0'); // Binding to 0.0.0.0 means remotes can connect
$webServer = new Ratchet\Server\IoServer(
        new Ratchet\Http\HttpServer(
        new Ratchet\WebSocket\WsServer(
        new Ratchet\Wamp\WampServer(
        $pusher
        )
        )
        ), $webSock
);

$loop->run();
JimQ
  • 23
  • 7
  • Your question doesn't seem to be about Ratchet. You have 0MQ client connection code that connects to a 0MQ server. Where is your 0MQ server code? I would guess that it is listening on port 5555, and this is why you can only connect to the queue on that port. I can't tell if it matters if the ports shared the same queue. If not I would expect you would need another 0MQ server running on a different port, and of course your 2nd client connection should work fine at that point. – gview Dec 13 '17 at 02:51
  • Well the code snippet above is basically from the ratchet docs, so i do think the question is about ratchet, however you pointed me in the right direction, i totally missed the part of the code that pushes the data, which was of course still connecting to 127.0.0.1:5555, i changed it to match the socket bindings and now it works, thank you :) – JimQ Dec 13 '17 at 22:58
  • I understand, but the point is that you are using an option to utilize 0MQ, and that was the problem -- not your ratchet server port binding. The libraries involved with 0MQ aren't part of Ratchet. At any rate, glad I was of help. – gview Dec 14 '17 at 02:12

0 Answers0