fuzzingserver.php 1.2 KB

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