| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
use Ratchet\ConnectionInterface;
|
|
|
3 |
|
|
|
4 |
require dirname(dirname(dirname(__DIR__))) . '/vendor/autoload.php';
|
|
|
5 |
|
|
|
6 |
class BinaryEcho implements \Ratchet\WebSocket\MessageComponentInterface {
|
|
|
7 |
public function onMessage(ConnectionInterface $from, \Ratchet\RFC6455\Messaging\MessageInterface $msg) {
|
|
|
8 |
$from->send($msg);
|
|
|
9 |
}
|
|
|
10 |
|
|
|
11 |
public function onOpen(ConnectionInterface $conn) {
|
|
|
12 |
}
|
|
|
13 |
|
|
|
14 |
public function onClose(ConnectionInterface $conn) {
|
|
|
15 |
}
|
|
|
16 |
|
|
|
17 |
public function onError(ConnectionInterface $conn, \Exception $e) {
|
|
|
18 |
}
|
|
|
19 |
}
|
|
|
20 |
|
|
|
21 |
$port = $argc > 1 ? $argv[1] : 8000;
|
|
|
22 |
$impl = sprintf('React\EventLoop\%sLoop', $argc > 2 ? $argv[2] : 'StreamSelect');
|
|
|
23 |
|
|
|
24 |
$loop = new $impl;
|
|
|
25 |
$sock = new React\Socket\Server('0.0.0.0:' . $port, $loop);
|
|
|
26 |
|
|
|
27 |
$wsServer = new Ratchet\WebSocket\WsServer(new BinaryEcho);
|
|
|
28 |
// This is enabled to test https://github.com/ratchetphp/Ratchet/issues/430
|
|
|
29 |
// The time is left at 10 minutes so that it will not try to every ping anything
|
|
|
30 |
// This causes the Ratchet server to crash on test 2.7
|
|
|
31 |
$wsServer->enableKeepAlive($loop, 600);
|
|
|
32 |
|
|
|
33 |
$app = new Ratchet\Http\HttpServer($wsServer);
|
|
|
34 |
|
|
|
35 |
$server = new Ratchet\Server\IoServer($app, $sock, $loop);
|
|
|
36 |
$server->run();
|