register("hello", function (Context $context) { // You don't have to, but you should return a promise from your // commands. return new Promise(function (callable $resolve) use ($context) { $resolve("Hello, {$context->name}"); }); }); // Create the CommandBus and pass the CommandRegistry $bus = new CommandBus($commands); $server = new SocketServer("tcp://127.0.0.1:9999"); $bus->addServer($server); // The server is sorted, now for the client! $client = new CommandBusClient(); $client->on(CommandBusClient::EVENT_CONNECTED, function () use ($client, $bus) { $client->execute('hello', ['name'=>'Bob']) ->then(function ($result) use ($client,$bus) { // Result from the call var_dump($result); // Shut down after receiving the response $bus->close(); $client->close(); }); } ); $client->connect("tcp://127.0.0.1:9999");