-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreceiverClient.php
More file actions
32 lines (25 loc) · 881 Bytes
/
receiverClient.php
File metadata and controls
32 lines (25 loc) · 881 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
use OpenSwoole\Coroutine;
Coroutine::run(function () {
$client = new \OpenSwoole\Coroutine\Http\Client('0.0.0.0', 8080);
$client->setHeaders([
"User-Agent" => 'Chrome/49.0.2587.3',
'Accept' => 'text/html,application/xhtml+xml,application/xml',
'Accept-Encoding' => 'gzip, deflate, br',
'Sec-WebSocket-Protocol' => 'wamp.2.json, wamp.2.msgpack'
]);
$upgraded = $client->upgrade('/');
Coroutine::create(function () use ($upgraded) {
if ($upgraded) {
}
});
Coroutine::create(function () use ($client) {
while ($client->connected) {
Coroutine::usleep(1);
$data = $client->recv();
Coroutine::create(function (\OpenSwoole\WebSocket\Frame $frame) {
echo 'Received: ' . $frame->data . PHP_EOL;
}, $data);
}
});
});