public function launch($profile)
 {
     $this->logger->info('Starting web socket');
     $stack = new Builder();
     /* @var $loop LoopInterface */
     $loop = Factory::create();
     $server = new Server($loop);
     $server->listen($this->port, $this->host);
     if (true === $profile) {
         $memoryUsagePeriodicTimer = new PeriodicMemoryUsage($this->logger);
         $this->periodicRegistry->addPeriodic($memoryUsagePeriodicTimer);
     }
     /** @var PeriodicInterface $periodic */
     foreach ($this->periodicRegistry->getPeriodics() as $periodic) {
         $loop->addPeriodicTimer($periodic->getTimeout(), [$periodic, 'tick']);
         $this->logger->info(sprintf('Register periodic callback %s, executed each %s seconds', $periodic instanceof ProxyInterface ? get_parent_class($periodic) : get_class($periodic), $periodic->getTimeout()));
     }
     $allowedOrigins = array_merge(array('localhost', '127.0.0.1'), $this->originRegistry->getOrigins());
     $stack->push('Ratchet\\Server\\IoServer', $server, $loop)->push('Ratchet\\Http\\HttpServer');
     if ($this->originCheck) {
         $stack->push('Gos\\Bundle\\WebSocketBundle\\Server\\App\\Stack\\OriginCheck', $allowedOrigins, $this->eventDispatcher);
     }
     $stack->push('Ratchet\\WebSocket\\WsServer')->push('Ratchet\\Session\\SessionProvider', $this->sessionHandler)->push('Ratchet\\Wamp\\WampServer');
     $app = $stack->resolve($this->wampApplication);
     /* Server Event Loop to add other services in the same loop. */
     $event = new ServerEvent($loop, $server);
     $this->eventDispatcher->dispatch(Events::SERVER_LAUNCHED, $event);
     $this->logger->info(sprintf('Launching %s on %s PID: %s', $this->getName(), $this->getAddress(), getmypid()));
     $app->run();
 }
Пример #2
0
 /**
  * @param bool $profile
  *
  * @throws \React\Socket\ConnectionException
  */
 public function launch($host, $port, $profile)
 {
     $this->logger->info('Starting web socket');
     //In order to avoid circular reference
     $this->topicManager->setWampApplication($this->wampApplication);
     $stack = new Builder();
     $server = new Server($this->loop);
     $server->listen($port, $host);
     if (true === $profile) {
         $memoryUsagePeriodicTimer = new PeriodicMemoryUsage($this->logger);
         $this->periodicRegistry->addPeriodic($memoryUsagePeriodicTimer);
     }
     /** @var PeriodicInterface $periodic */
     foreach ($this->periodicRegistry->getPeriodics() as $periodic) {
         $this->loop->addPeriodicTimer($periodic->getTimeout(), [$periodic, 'tick']);
         $this->logger->info(sprintf('Register periodic callback %s, executed each %s seconds', $periodic instanceof ProxyInterface ? get_parent_class($periodic) : get_class($periodic), $periodic->getTimeout()));
     }
     $allowedOrigins = array_merge(array('localhost', '127.0.0.1'), $this->originRegistry->getOrigins());
     $stack->push('Ratchet\\Server\\IoServer', $server, $this->loop)->push('Ratchet\\Http\\HttpServer');
     if ($this->originCheck) {
         $stack->push('Gos\\Bundle\\WebSocketBundle\\Server\\App\\Stack\\OriginCheck', $allowedOrigins, $this->eventDispatcher);
     }
     $stack->push('Ratchet\\WebSocket\\WsServer')->push('Gos\\Bundle\\WebSocketBundle\\Server\\App\\Stack\\WampConnectionPeriodicTimer', $this->loop)->push('Ratchet\\Session\\SessionProvider', $this->sessionHandler)->push('Ratchet\\Wamp\\WampServer', $this->topicManager);
     $app = $stack->resolve($this->wampApplication);
     //Push Transport Layer
     foreach ($this->serverPusherHandlerRegistry->getPushers() as $handler) {
         try {
             $handler->handle($this->loop, $this->wampApplication);
         } catch (\Exception $e) {
             $this->logger->error($e->getMessage(), ['code' => $e->getCode(), 'file' => $e->getFile(), 'line' => $e->getLine(), 'push_handler_name' => $handler->getName()]);
         }
     }
     /* Server Event Loop to add other services in the same loop. */
     $event = new ServerEvent($this->loop, $server);
     $this->eventDispatcher->dispatch(Events::SERVER_LAUNCHED, $event);
     $this->logger->info(sprintf('Launching %s on %s PID: %s', $this->getName(), $host . ':' . $port, getmypid()));
     $app->run();
 }