forked from rsocket/rsocket-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrsocket-client.php
More file actions
34 lines (25 loc) · 887 Bytes
/
Copy pathrsocket-client.php
File metadata and controls
34 lines (25 loc) · 887 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
require 'vendor/autoload.php';
use RSocket\Payload;
use RSocket\RSocket;
use RSocket\RSocketConnector;
use Rx\Observable;
use Rx\Scheduler;
$loop = React\EventLoop\Factory::create();
/** @noinspection PhpUnhandledExceptionInspection */
Scheduler::setDefaultFactory(function () use ($loop) {
return new Scheduler\EventLoopScheduler($loop);
});
$rsocketCall = function (RSocket $rsocket) {
$observablePayload = $rsocket->requestResponse(Payload::fromText("text/plain", "Ping"));
$observablePayload->subscribe(
function (Payload $payload) {
echo 'Result: ' . $payload->getDataUtf8() . PHP_EOL;
}
);
};
$rsocketPromise = RSocketConnector::create($loop)->connect("tcp://127.0.0.1:42252");
$rsocketPromise->then($rsocketCall);
$target = Observable::fromPromise($rsocketPromise);
$target->map($rsocketCall)->subscribe();
$loop->run();