Ejemplo n.º 1
0
 public function __construct(SocketServerInterface $io)
 {
     $this->io = $io;
     $this->io->on('connection', function (ConnectionInterface $conn) {
         var_dump($conn);
     });
 }
Ejemplo n.º 2
0
 /**
  * Server constructor.
  *
  * @param ServerInterface         $server
  * @param RequestHandlerInterface $requestHandler
  */
 public function __construct(ServerInterface $server, RequestHandlerInterface $requestHandler)
 {
     $this->server = $server;
     $this->requestHandler = $requestHandler;
     $this->server->on('connection', function (ConnectionInterface $connection) {
         $this->handleConnection($connection);
     });
 }
Ejemplo n.º 3
0
 /**
  * Runs the message server on the given port.
  *
  * @param string  $consumer Command to execute when a message arrives
  * @param integer $port     Port to run the server on
  *
  * @return void
  */
 public function run($consumer, $port, $callback = null)
 {
     // @codeCoverageIgnoreStart
     $this->socket->on('connection', function (ConnectionInterface $conn) use($consumer, $callback) {
         $conn->on('data', function ($data) use($conn, $consumer, $callback) {
             $this->handleData(trim($data), $consumer, $conn, $callback);
         });
     });
     // @codeCoverageIgnoreEnd
     $this->socket->listen($port);
     $this->loop->run();
 }
Ejemplo n.º 4
0
 public function __construct(ServerInterface $socket, LoopInterface $loop, ProtocolFactory $protocol = null, Invoker $business = null)
 {
     if ($protocol === null) {
         $protocol = new ProtocolFactory();
     }
     $this->databases = array(new Storage('0'), new Storage('1'));
     $db = reset($this->databases);
     if ($business === null) {
         $business = new Invoker($protocol->createSerializer());
         $business->addCommands(new Business\Connection($this));
         $business->addCommands(new Business\Keys($db));
         $business->addCommands(new Business\Lists($db));
         $business->addCommands(new Business\Server($this));
         $business->addCommands(new Business\Strings($db));
         $business->renameCommand('x_echo', 'echo');
     }
     $this->socket = $socket;
     $this->loop = $loop;
     $this->protocol = $protocol;
     $this->business = $business;
     $this->clients = new SplObjectStorage();
     $this->config = new Config();
     $this->on('error', function ($error, Client $client) {
         $client->end();
     });
     $socket->on('connection', array($this, 'handleConnection'));
 }
Ejemplo n.º 5
0
 public function __construct(ServerInterface $serverInterface, LoopInterface $loop, ConnectorInterface $connector)
 {
     $this->loop = $loop;
     $this->connector = $connector;
     $that = $this;
     $serverInterface->on('connection', function ($connection) use($that) {
         $that->emit('connection', array($connection));
         $that->onConnection($connection);
     });
 }
Ejemplo n.º 6
0
 /**
  * @param Ratchet\MessageComponentInterface The Ratchet application stack to host
  * @param React\Socket\ServerInterface The React socket server to run the Ratchet application off of
  * @param React\EventLoop\LoopInterface The React looper to run the Ratchet application off of
  */
 public function __construct(MessageComponentInterface $app, ServerInterface $socket, LoopInterface $loop)
 {
     gc_enable();
     set_time_limit(0);
     ob_implicit_flush();
     $this->loop = $loop;
     $this->app = $app;
     $socket->on('connection', array($this, 'handleConnect'));
     $this->handlers['data'] = array($this, 'handleData');
     $this->handlers['end'] = array($this, 'handleEnd');
     $this->handlers['error'] = array($this, 'handleError');
 }
Ejemplo n.º 7
0
 /**
  * @param \Ratchet\MessageComponentInterface  $app      The Ratchet application stack to host
  * @param \React\Socket\ServerInterface       $socket   The React socket server to run the Ratchet application off of
  * @param \React\EventLoop\LoopInterface|null $loop     The React looper to run the Ratchet application off of
  */
 public function __construct(MessageComponentInterface $app, ServerInterface $socket, LoopInterface $loop = null)
 {
     if (false === strpos(PHP_VERSION, "hiphop")) {
         gc_enable();
     }
     set_time_limit(0);
     ob_implicit_flush();
     $this->loop = $loop;
     $this->app = $app;
     $socket->on('connection', array($this, 'handleConnect'));
     $this->handlers = new \SplFixedArray(3);
     $this->handlers[0] = array($this, 'handleData');
     $this->handlers[1] = array($this, 'handleEnd');
     $this->handlers[2] = array($this, 'handleError');
 }
Ejemplo n.º 8
0
 /**
  * @param ServerInterface $socketServer
  * @param MiddlewareQueueInterface $queue
  */
 public function __construct(ServerInterface $socketServer, MiddlewareQueueInterface $queue)
 {
     $this->socketServer = $socketServer;
     $this->socketServer->on('connection', [$this, 'connection']);
     $this->queue = $queue;
 }