Ratchet PHP: Bind to different port than 127.0.0.1:5555

1.6k views Asked by At

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();
0

There are 0 answers