Completed
Push — master ( e22a05...c980a2 )
by Maxime
9s
created

EchoServer::onBinary()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
use Nekland\Woketo\Server\Websocket;
4
5
require 'vendor/autoload.php';
6
7
$foo = new Websocket(9001);
8
9
10
11
class EchoServer implements \Nekland\Woketo\Message\MessageHandlerInterface
12
{
13
    public function onConnection(\Nekland\Woketo\Server\Connection $connection)
14
    {
15
    }
16
17
    public function onMessage(string $data, \Nekland\Woketo\Server\Connection $connection)
18
    {
19
        $connection->write($data);
20
    }
21
22
    public function onBinary(string $data, \Nekland\Woketo\Server\Connection $connection)
23
    {
24
        $connection->write($data, \Nekland\Woketo\Rfc6455\Frame::OP_BINARY);
25
    }
26
27
    public function onError(\Nekland\Woketo\Exception\WebsocketException $e, \Nekland\Woketo\Server\Connection $connection)
28
    {
29
        echo '(' . get_class($e) . ') ' . $e->getMessage() . "\n";
30
    }
31
}
32
33
$foo->setMessageHandler(new EchoServer());
34
35
36
$foo->start();
37
38