protected function execute(InputInterface $input, OutputInterface $output) { $chat = $this->getContainer()->get('chat'); $server = IoServer::factory(new HttpServer(new WsServer($chat)), 8080); $server->run(); echo "Server started"; }
/** * Start Server */ public function start() { $loop = $this->createLoop(); $socket = $this->createSocket($loop, $this->port, $this->address); $ioServer = new IoServer($this->component, $socket, $loop); $this->logStart(); $ioServer->run(); }
/** * Execute the console command. * * @return mixed */ public function fire() { $port = intval($this->option('port')); $this->info("Starting chat web socket server on port " . $port); $server = IoServer::factory(new HttpServer(new WsServer(new Chat())), 8082); $server->run(); }
/** * Execute the console command. * * @return mixed */ public function fire() { $port = env('SOCKET_PORT'); $this->info('Websocket is running on port ' . $port); $server = IoServer::factory(new HttpServer(new WsServer(new \App\Services\Websocket())), $port); $server->run(); }
protected function execute(InputInterface $input, OutputInterface $output) { $this->input = $input; $this->output = $output; declare (ticks=1); register_shutdown_function(array($this, 'stopCommand')); set_error_handler(array($this, 'errorHandler')); if (function_exists("pcntl_signal")) { pcntl_signal(SIGTERM, [$this, 'stopCommand']); pcntl_signal(SIGINT, [$this, 'stopCommand']); } else { } $this->isDebug = $input->getArgument('isDebug'); $port = $input->getOption('port'); $chat = $this->container->get('app.chat.handler'); $chat->setIsDebug($this->isDebug); $messageManager = new MessageManager($chat); $messageManager->setIsDebug($this->isDebug); $server = IoServer::factory(new HttpServer(new WsServer($messageManager)), $port); if ($this->isDebug) { $redis = $this->container->get('snc_redis.default'); $server->loop->addPeriodicTimer(5, function () use($redis, $messageManager) { $memory = memory_get_usage(); echo "Send messages. Redis value: " . $redis->get('value') . "\r\n"; $info = array(); $info['message'] = "Redis value: " . $redis->get('value') . "; Memory: " . $memory; $info['type'] = 'message'; $info['from'] = 'me'; $messageManager->sendAll(json_encode($info)); }); } $this->logMessage("Start server."); $server->run(); $this->logMessage("Finish execute daemon."); }
public function execute(InputInterface $input, OutputInterface $output) { /** * @var \Symfony\Component\Console\Helper\FormatterHelper */ $formatter = $this->getHelper('formatter'); $output->writeln($formatter->formatSection('IO', 'Start development server')); // $loop = \React\EventLoop\Factory::create(); $bridgeName = $input->getOption('bridge'); switch (strtolower($bridgeName)) { case 'phalcony': $bridge = new Phalcony(); break; case 'hello': default: $bridge = new SimpleBridge(); break; } $bridge->on('open', function (ConnectionInterface $conn, RequestInterface $request = null) use(&$formatter, $output) { $section = $formatter->formatSection('IO', 'Connection is open from ' . $request->getHost() . ' on ' . date('h:i:s') . ' : ' . $request->getUrl()); $output->writeln($section); }); $bridge->on('close', function (ConnectionInterface $conn, $timer) use(&$formatter, $output) { $output->writeln($formatter->formatSection('IO', sprintf('Connection is closed. Request completed %.4F sec.', $timer))); }); $bridge->on('error', function (Exception $e) use(&$formatter, $output) { $output->writeln($formatter->formatBlock(array('[App]', $e->getMessage(), 'in the ' . $e->getFile() . ' file on ' . $e->getLine() . ' line'), 'error')); }); $listen = $input->getOption('listen'); $port = $input->getOption('port'); $server = IoServer::factory(new HttpServer($bridge), $port, $listen); $server->run(); }
/** * Execute the console command. * * @return mixed */ public function handle() { $this->info('Starting web socket server...'); $this->server = IoServer::factory(new HttpServer(new WsServer(new Chat())), 8080, '0.0.0.0'); $this->info('To stop the web socket server press "Ctrl" + "C"'); $this->server->run(); }
/** * Execute the console command. * * @return mixed */ public function handle() { $port = intval($this->argument('port')); $this->info("Starting chat web socket server on port " . $port); $server = IoServer::factory(new HttpServer(new WsServer(new ChatController())), $port); $server->run(); }
private function startServer() { $ip = $this->config['server']['host']; $port = $this->config['server']['port']; $server = IoServer::factory(new HttpServer(new WsServer(new \Fr\DiffSocket\Server($this->config))), $port, $ip); echo "Server started on {$ip}:{$port}\n"; $server->run(); }
/** * @param AbstractMultiRoomServer $chatServer * @param int $port * @param string $ip * @return IoServer */ public static function run(AbstractMultiRoomServer $chatServer, $port, $ip = '0.0.0.0') { $wsServer = new WsServer($chatServer); $http = new HttpServer($wsServer); $server = IoServer::factory($http, $port, $ip); $server->run(); return $server; }
/** * @param Chat $chatServer * @param int $port * @param string $ip * @return IoServer */ public static function run(Chat $chatServer, $port, $ip = '127.0.0.1') { $wsServer = new WsServer($chatServer); $http = new HttpServer($wsServer); $server = IoServer::factory($http, $port, $ip); $server->run(); return $server; }
protected function execute(InputInterface $input, OutputInterface $output) { $port = $input->getOption('port'); $address = $input->getOption('address'); $server = IoServer::factory(new HttpServer(new WsServer(new Server($this->getContainer()->get('croupier')))), $port, $address); $output->writeln(sprintf('<info>Starting Croupier server on %s:%d.</info>', $address, $port)); $server->run(); }
public function newWorker($output, $formatter, $listen, $port, $bridge) { $pid = pcntl_fork(); if (!$pid) { $output->writeln($formatter->formatSection('App', 'Start slave worker on ' . $listen . ':' . $port . ' pid: ' . $pid)); $this->slots[] = $server = IoServer::factory(new HttpServer($bridge), $port, $listen); $server->run(); } }
/** * Execute the console command. * * @return mixed */ public function handle() { $address = $this->option('address'); $port = intval($this->option('port')); $this->info('Starting web socket server on port ' . $port); $server = IoServer::factory(new HttpServer(new WsServer($this->connection)), $port, $address); $this->connection->setServer($server); $server->run(); }
protected function execute(InputInterface $input, OutputInterface $output) { //$chat = $this->getContainer()->get('heliosblog.chat'); $memcache = new \Memcache(); $memcache->connect('localhost', 11211); $server = IoServer::factory(new HttpServer(new WsServer(new SessionProvider(new Chat1(), new Handler\MemcacheSessionHandler($memcache)))), 8080); echo "Chat server is running\n"; $server->run(); }
protected function execute(InputInterface $input, OutputInterface $output) { $port = $input->getOption('port'); if (!$port) { $port = 4567; } $server = IoServer::factory(new HttpServer(new WsServer($this->getContainer()->get('tetris.socket_server'))), $port); $output->writeln("Server running on port {$port}"); $server->run(); }
/** * Execute the console command. * * @return mixed */ public function fire() { $port = (int) $this->option("port"); if (!$port) { $port = 7778; } $server = IoServer::factory(new HttpServer(new WsServer($this->chat)), $port); $this->line("<info>Listening on port <comment>" . $port . "</comment>.</info>"); $server->run(); }
public function startAction() { $request = $this->getRequest(); if (!$request instanceof ConsoleRequest) { throw new \RuntimeException('You can only use this action from a console!'); } $config = $this->getServiceLocator()->get('Config'); $server = IoServer::factory(new HttpServer(new WsServer(new ShoppingList())), $config['web_sockets']['port']); echo 'Running...' . PHP_EOL; $server->run(); }
/** * Execute the console command. * * @return void */ public function fire() { echo 'Iniciando servidor...' . PHP_EOL; $controller = new Controller(); $server = IoServer::factory(new HttpServer(new WsServer($controller)), 777); $loop = $server->loop; $loop->addPeriodicTimer(5, function () use($controller) { $controller->sendCounterMessage(); }); $server->run(); }
public function start($adress = '127.0.0.1', $port = 8000, $ssl = false) { $memcache = new \Memcache(); $memcache->connect('localhost', 11211); $chat = new Chat(); $handler = new Handler\MemcacheSessionHandler($memcache, array('prefix' => '')); $session = new SessionProvider($chat, $handler, array('adapter' => 'Php', 'session.name' => 'PHPSESSID', 'session.save_handler' => 'memcached', 'session.save_path' => 'localhost:11211')); // Run the server application through the WebSocket protocol on port 8000 $server = IoServer::factory(new WsServer($session), 8000); $server->run(); }
public function fire() { // Query logları tutulmasın // Server uzun süre çalıştığında memory leak sorunu yaratır DB::connection()->enableQueryLog(); // Tüm userları offline yap. User::where('status', 1)->update(['status' => 0]); // Websocket Serverını Çalıştır $server = IoServer::factory(new HttpServer(new WsServer(new ChatServer())), env("WS_PORT")); $server->run(); }
/** * Initialization action */ public function actionRun() { set_error_handler([$this, 'errorHandler']); echo 'Trying to start server...' . PHP_EOL; $server = IoServer::factory(new HttpServer(new WsServer(new ServerProcess())), 3084); try { $server->run(); } catch (\Exception $e) { echo "Catch new process exception: {$e->getMessage()}" . PHP_EOL; } echo 'Server was started successfully. Setup logging to get more details.' . PHP_EOL; }
/** * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln("Starting server"); $manager = $this->getContainer()->get("bordeux.websocket.service.connection.manager"); $manager->setOutput($output); $ws = new WsServer($manager); $ws->disableVersion(0); $server = IoServer::factory(new HttpServer($ws), (int) $input->getOption('port'), $input->getOption('ip')); $manager->setLoop($server->loop); $routingManager = $this->getContainer()->get("bordeux.websocket.service.routing.manager"); $routingManager->setConnectionManager($manager); $manager->setRoutes($routingManager->findRoutes()); $server->run(); }
/** * Runs the RBEGame Server * @param integer $port The port number to run the server on * @param boolean $connectToRegistries Whether you want to connect one or more registry websites */ public function actionRun($port = 8080, $connectToRegistries = true) { $this->Server = new Server(); if ($connectToRegistries) { $AuthClient = $this->connectToRegistries(); if ($AuthClient) { $Server->addAuthClient($AuthClient); } } $s = IoServer::factory(new HttpServer(new WsServer($this->Server)), $port); $s->socket->on('end', [$this, 'cleanUp']); $this->Server->registerTimers($s); $s->run(); }
/** * This method initialize the socket server * */ public function socket_server() { if (!is_cli()) { echo "This controller must run from command line interface only.\n"; return; } echo __DIR__; $this->load->library('websocket_application'); $this->load->model('user_model'); $loop = Factory::create(); $socket = new Server($loop); $socket->listen('8087', '0.0.0.0'); echo "Created websocket: ws://0.0.0.0:8087/\n"; $routes = new RouteCollection(); $users = $this->user_model->get_records(); foreach ($users as $user) { $routes->add($user->record_id, new Route('/' . $user->record_id, array('_controller' => new WsServer(new Websocket_application())))); echo "Created route: /" . $user->record_id . "\n"; } $context = new RequestContext(); $matcher = new UrlMatcher($routes, $context); $server = new IoServer(new HttpServer(new Router($matcher)), $socket, $loop); $server->run(); }
protected function execute(InputInterface $input, OutputInterface $output) { $time_start = microtime(true); $container = $this->getApplication()->getKernel()->getContainer(); /*$server = new \Ratchet\App('127.0.0.1',1337); $server->route('/pubsub', new XxamPubSub); $server->route('/websocket', new \Ratchet\Server\EchoServer, array('*')); $server->run(); */ $server = IoServer::factory(new HttpServer(new WsServer(new XxamChat())), 1337); $server->run(); $time_end = microtime(true); $time = $time_end - $time_start; $returntext = "\n<info>OK in {$time} Sekunden.</info>"; $output->writeln($returntext); }
/** * */ public function websocketListenAction($argv) { $config = $this->di->getConfig(); $params = $this->parseArgs($argv, ['title' => 'Start the websocket listener (start this through the server command).', 'args' => ['required' => [], 'optional' => []], 'opts' => ['p|wsport:' => "websockets listen on port (default is {$config->app->wsPort}).", 'z|zmqport:' => "zmq listen on port (default is {$config->app->zmqPort})."]]); // $this->ensureRunningAsWebUser(); $opts = $params['opts']; $config = $this->config; $wsPort = isset($opts['wsport']) ? $opts['wsport'] : $config->app->wsPort; $zmqPort = isset($opts['zmqport']) ? $opts['zmqport'] : $config->app->zmqPort; $loop = EventLoopFactory::create(); $chat = new Chat(); $chat->setDI($this->getDI()); // Listen for the web server to make a ZeroMQ push after an ajax request // $context = new ZMQContext($loop); // $pull = $context->getSocket(ZMQ::SOCKET_PULL); // $pull->bind("tcp://127.0.0.1:${zmqPort}"); // Binding to 127.0.0.1 means the only client that can connect is itself // $pull->on('message', [$chat, 'onUserJoin']); $wsServer = new WsServer($chat); $ioServer = IoServer::factory(new HttpServer($wsServer), $wsPort); echo "websocket listening on port {$wsPort} in " . ENV . " mode\n"; $ioServer->run(); }
protected function execute(InputInterface $input, OutputInterface $output) { $this->io = new SymfonyStyle($input, $output); $this->io->block('Running server...'); $verbosity = $this->io->getVerbosity(); switch ($verbosity) { case 16: $verbosity = 'quiet'; break; case 32: $verbosity = 'normal'; break; case 64: $verbosity = 'verbose'; break; case 128: $verbosity = 'very_verbose'; break; case 256: $verbosity = 'debug'; break; } $this->io->note('Verbosity is "' . $verbosity . '". To set verbosity, add "-v", "-vv" or "-vvv" end the end of this command.'); $this->socketPort = $this->getContainer()->getParameter('socket_port'); $em = $this->getContainer()->get('doctrine.orm.default_entity_manager'); $logger = $this->getContainer()->get('logger'); $socketUrl = $this->getContainer()->getParameter('socket_server_url'); $webUrl = $this->getContainer()->getParameter('web_server_url'); $webHooks = $em->getRepository('AppBundle:WebHook')->findAll(); $logger->info(count($webHooks) . ' webHook(s)'); $server = new Server($em, $webHooks, $webUrl, $socketUrl, $logger); $this->killExistingSocketServer(); $ioServer = IoServer::factory(new HttpServer(new WsServer($server)), $this->socketPort); $logger->info('Run socket server on port ' . $this->socketPort . '...'); $ioServer->run(); }
<?php $vendorPath = dirname(__DIR__) . '/vendor/autoload.php'; if (file_exists($vendorPath)) { include $vendorPath; } // Your shell script use Ratchet\Http\HttpServer; use Ratchet\Server\IoServer; $http = new HttpServer(new MyWebPage()); $server = IoServer::factory($http); $server->run();
<?php require_once dirname(__FILE__) . '/vendor/autoload.php'; use React\Stream\Stream; use Ratchet\WebSocket\WsServer; use Ratchet\Http\HttpServer; use Ratchet\Server\IoServer; use Monolog\Logger; use Monolog\Handler\StreamHandler; $host = '0.0.0.0'; $port = 7171; $pubSubChannel = new Nawarian\Server\PubSubChannel(); $wsServer = IoServer::factory(new HttpServer(new WsServer($pubSubChannel)), $port, $host); $loop = $wsServer->loop; $logStream = new Stream(STDOUT, $loop); $logFileStream = new Stream(fopen(dirname(__FILE__) . '/logs/server.log', 'w'), $loop); $logger = new Logger('main'); $logger->pushHandler(new StreamHandler($logStream->stream)); $logger->pushHandler(new StreamHandler($logFileStream->stream)); $pubSubChannel->logger = $logger; $pubSubChannel->configureSocketServer($host, $port, $loop); $wsServer->run();