public function __construct(SocketServerInterface $io) { $this->io = $io; $this->io->on('connection', function (ConnectionInterface $conn) { var_dump($conn); }); }
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')); }
/** * 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); }); }
/** * @param array $options * @param array $arguments * @return mixed */ public function run(array $options, array $arguments) { $port = isset($arguments[0]) ? $arguments[0] : "8001"; $host = isset($arguments[1]) ? $arguments[1] : "0.0.0.0"; /** @var \Castle23\Http\Server $server */ $server = $this->container->getInstanceOf(Server::class); $this->socket->listen($port, $host); $this->loop->run(); }
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); }); }
/** * {@inheritdoc} */ public function stop() { if (null !== $this->loop) { $this->loop->stop(); $this->httpServer->removeAllListeners(); $this->httpServer = null; $this->socketServer->shutdown(); $this->socketServer = null; $this->loop = null; } }
/** * @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'); }
/** * 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(); }
/** * Run react. * * @param int $port * @param string $host */ public function run($port, $host) { $request_handler = function (Request $request, Response $response) { echo $request->getMethod() . ' ' . $request->getPath() . PHP_EOL; $sf_request = $this->request_bridge->convertRequest($request); $sf_response = $this->app->handle($sf_request); $this->app->terminate($sf_request, $sf_response); $this->response_bridge->send($response, $sf_response); }; $this->http->on('request', $request_handler); $this->socket->listen($port, $host); $this->loop->run(); }
/** * @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'); }
/** * Find a free port for the server and start it. * @param int $minPort Min port in range (inclusive). * @param int $maxPort Max port in range (inclusive). * @param int $port Actual selected port (output). */ protected function startServer($minPort, $maxPort, &$port) { if ($minPort > $maxPort) { throw new InitException("Invalid port range min ({$minPort}) is bigger than max ({$maxPort})."); } $retries = 0; $connected = false; while (!$connected && $retries < self::SERVER_START_RETRIES) { $port = rand($minPort, $maxPort); try { $this->server->listen($port); $connected = true; } catch (ConnectionException $e) { $retries++; if ($retries >= self::SERVER_START_RETRIES) { throw new InitException("Failed to start server " . $e->getMessage(), $e); } } } }
/** * @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; }