-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrsocket-server.php
More file actions
29 lines (24 loc) · 934 Bytes
/
Copy pathrsocket-server.php
File metadata and controls
29 lines (24 loc) · 934 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
<?php
/** @noinspection PhpUnusedParameterInspection */
require 'vendor/autoload.php';
use React\EventLoop\Loop;
use RSocket\AbstractRSocket;
use RSocket\CallableSocketAcceptor;
use RSocket\Payload;
use RSocket\RSocketServer;
use Rx\Observable;
use Rx\Scheduler;
/** @noinspection PhpUnhandledExceptionInspection */
Scheduler::setDefaultFactory(static function () {
return new Scheduler\EventLoopScheduler(Loop::get());
});
$listenUrl = "tcp://127.0.0.1:42252";
$socketAcceptor = CallableSocketAcceptor::handle(static function ($setupPayload, $sendingRSocket) {
return AbstractRSocket::requestResponseHandler(static function ($payload) {
print('Received:' . $payload->getDataUtf8() . PHP_EOL);
return Observable::of(Payload::fromText("metadata", "PONG"));
});
});
$server = RSocketServer::create($socketAcceptor)->bind($listenUrl);
echo "RSocket Server started on ${listenUrl}\n";
Loop::get()->run();