Ratchet: how to use chat and push notifications on the same server

I would like to use both chat and push notifications applications on the same server, starting with the ratchet tutorial ( http://socketo.me ) - Hello World ( http://socketo.me/docs/hello-world ) - "push integration" with ZMQ.
each application works well, I run chat-server.php (for chat) and push-server.php (for integration with push). But when I open two cmd windows and run them, it does not work. This may be a stupid question, but I'm new to this area.

find the code as executable


chat-server.php:

use Ratchet \ Server \ IoServer; use MyApp \ Chat;

require dirname(__DIR__) . '/vendor/autoload.php';

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

$server->run();

push-server.php:

require dirname(__DIR__) . '/vendor/autoload.php';

$loop   = React\EventLoop\Factory::create();
$pusher = new MyApp\Pusher;

// 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('tcp://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, 'onBlogEntry'));

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

.

+4

All Articles