当前位置: 首页>>代码示例>>PHP>>正文


PHP Socket\Server类代码示例

本文整理汇总了PHP中React\Socket\Server的典型用法代码示例。如果您正苦于以下问题:PHP Server类的具体用法?PHP Server怎么用?PHP Server使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Server类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 public function __construct(QueueContextInterface $queueContext, LoopInterface $eventLoop, $port)
 {
     $this->queueContext = $queueContext;
     $server = new Server($eventLoop);
     $server->on('connection', [$this, 'onConnection']);
     $server->listen($port);
 }
开发者ID:PHPQ,项目名称:Server,代码行数:7,代码来源:ProducerServer.php

示例2: start

 public function start()
 {
     $loop = React\EventLoop\Factory::create();
     $socket = new React\Socket\Server($loop);
     $server = $this;
     $socket->on(self::CONNECTION, function (React\Socket\Connection $connection) use(&$server) {
         $server->connectionEvent($connection);
         $connection->on(SyncDaemonServer::DATA, function ($data) use(&$connection, &$server) {
             list($command, $name) = explode(' ', $data);
             if ($command == SyncDaemonServer::ACQUIRE) {
                 $server->acquireCommand($connection, $name);
             }
             if ($command == SyncDaemonServer::RELEASE) {
                 $server->releaseCommand($connection, $name);
             }
         });
         $connection->on(SyncDaemonServer::CLOSE, function () use(&$connection, &$server) {
             $server->closeEvent($connection);
         });
         $connection->write(SyncDaemonServer::ACCEPT);
     });
     //debug
     //$loop->addPeriodicTimer(1, function () use (&$server) {
     //    var_dump(count($server->connections) . '-' . count($server->locks));
     //});
     $socket->listen($this->port, $this->host);
     $loop->run();
 }
开发者ID:ivixlabs,项目名称:sync-daemon,代码行数:28,代码来源:SyncDaemonServer.php

示例3: setupSocketListeners

 private function setupSocketListeners()
 {
     $connectionListeners = array();
     foreach ($this->socketListeners as $listener) {
         /** @var SocketListenerInterface $service */
         $service = $this->getContainer()->get($listener);
         if (!$service instanceof SocketListenerInterface) {
             throw new \Exception("Socket Listener Services must implement JDare/ClankBundle/Server/SocketListenerInterface");
         }
         foreach ((array) $service->getListeners() as $event => $callback) {
             if ($event == 'connection') {
                 $this->socket->on('connection', $callback);
             } elseif ($event == 'error') {
                 $this->socket->on('error', $callback);
             } else {
                 if (!isset($connectionListeners[$event])) {
                     $connectionListeners[$event] = array();
                 }
                 $connectionListeners[$event][] = $callback;
             }
         }
     }
     if (!empty($connectionListeners)) {
         $this->socket->on('connection', function (ConnectionInterface $conn) use(&$connectionListeners) {
             $conn->on('data', function ($data) use($conn, &$connectionListeners) {
                 if (isset($connectionListeners[$data])) {
                     foreach ($connectionListeners[$data] as $callback) {
                         $callback($conn);
                     }
                 }
             });
         });
     }
 }
开发者ID:adamus-tork,项目名称:ClankBundle,代码行数:34,代码来源:WebSocketServerType.php

示例4: start

 /**
  * Start the HTTP Server
  */
 public function start()
 {
     $this->httpServer->on('request', [$this, 'handleRequest']);
     $this->logger->info("Server is listening at " . $this->configuration['listen']['host'] . ":" . $this->configuration['listen']['port']);
     $this->socketServer->listen($this->configuration['listen']['port'], $this->configuration['listen']['host']);
     $this->eventLoop->run();
 }
开发者ID:thinframe,项目名称:server,代码行数:10,代码来源:Server.php

示例5: addListener

 public function addListener($host = '127.0.0.1', $port = 8080, $use_ssl = false, $cert = null)
 {
     $proxy = new Server($this->loop);
     $proxy->on('connection', new ConnectionHandler($this));
     $context = !$use_ssl ? [] : ['ssl' => ['local_cert' => $cert === null ? __DIR__ . '/../certificate.pem' : $cert, 'allow_self_signed' => true, 'verify_peer' => false]];
     $proxy->listen($port, $host, $context);
 }
开发者ID:mpyw,项目名称:php-hyper-builtin-server,代码行数:7,代码来源:Master.php

示例6: listen

 /**
  * Creates a new \React\Http\Server and runs it
  *
  * @param int $port
  */
 public function listen($port)
 {
     $socket = new SocketServer($this->loop);
     $server = new HttpServer($socket);
     $server->on('request', $this->requestHandler);
     $socket->listen($port);
 }
开发者ID:voidcontext,项目名称:arc-reactor,代码行数:12,代码来源:ReactHttpServer.php

示例7: fire

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     // create a log channel
     $log = new Logger('websocket');
     $log->pushHandler(new RotatingFileHandler(storage_path() . '/logs/websocket.log', 10, Logger::DEBUG));
     $config = Config::get('announcements-server');
     $loop = LoopFactory::create();
     $announcements = new AnnouncementsWebSocket($log);
     // Listen for the web server to make a message push.
     $broadcast = 'tcp://' . $config['broadcast']['ip'] . ':' . $config['broadcast']['port'];
     $this->info('Starting broadcast socket on ' . $broadcast);
     $context = new ZMQContext($loop);
     $broadcastSocket = $context->getSocket(ZMQ::SOCKET_PULL);
     $broadcastSocket->bind($broadcast);
     $broadcastSocket->on('message', array($announcements, 'onBroadcast'));
     // Listen for status check.
     $status = 'tcp://' . $config['status']['ip'] . ':' . $config['status']['port'];
     $this->info('Starting status socket on ' . $status);
     $statusSock = new SocketServer($loop);
     $statusSock->listen($config['status']['port'], $config['status']['ip']);
     new IoServer(new AnnouncementsServerStatus(), $statusSock);
     // Listen for WebSocket connections.
     $wsPort = $config['websocket']['port'];
     $wsIp = $config['websocket']['ip'];
     $this->info('Starting WebSocket socket on ws://' . $wsIp . ':' . $wsPort);
     $webSock = new SocketServer($loop);
     $webSock->listen($wsPort, $wsIp);
     new IoServer(new HttpServer(new WsServer($announcements)), $webSock);
     // Ping all clients each 2 min.
     $loop->addPeriodicTimer(120, function () use($announcements) {
         $announcements->ping();
     });
     $log->info('Server started');
     $loop->run();
 }
开发者ID:fencer-md,项目名称:stoticlle,代码行数:40,代码来源:AnnouncementsServer.php

示例8: __construct

 /**
  * @param string        $httpHost HTTP hostname clients intend to connect to. MUST match JS `new WebSocket('ws://$httpHost');`
  * @param int           $port     Port to listen on. If 80, assuming production, Flash on 843 otherwise expecting Flash to be proxied through 8843
  * @param string        $address  IP address to bind to. Default is localhost/proxy only. '0.0.0.0' for any machine.
  * @param LoopInterface $loop     Specific React\EventLoop to bind the application to. null will create one for you.
  */
 public function __construct($httpHost = 'localhost', $port = 8080, $address = '127.0.0.1', LoopInterface $loop = null, $context = array())
 {
     if (extension_loaded('xdebug')) {
         trigger_error("XDebug extension detected. Remember to disable this if performance testing or going live!", E_USER_WARNING);
     }
     if (3 !== strlen('✓')) {
         throw new \DomainException('Bad encoding, length of unicode character ✓ should be 3. Ensure charset UTF-8 and check ini val mbstring.func_autoload');
     }
     if (null === $loop) {
         $loop = LoopFactory::create();
     }
     $this->httpHost = $httpHost;
     $socket = new Reactor($loop, $context);
     $socket->listen($port, $address);
     $this->routes = new RouteCollection();
     $this->_server = new IoServer(new HttpServer(new Router(new UrlMatcher($this->routes, new RequestContext()))), $socket, $loop);
     $policy = new FlashPolicy();
     if ('*' !== $httpHost) {
         $policy->addAllowedAccess($httpHost, 80);
         $policy->addAllowedAccess($httpHost, $port);
     }
     $flashSock = new Reactor($loop);
     $this->flashServer = new IoServer($policy, $flashSock);
     if (80 == $port) {
         $flashSock->listen(843, '0.0.0.0');
     } else {
         $flashSock->listen(8843);
     }
 }
开发者ID:Rudi9719,项目名称:stein-syn,代码行数:35,代码来源:App.php

示例9: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // Make sure that websockets are enabled in the config so that the proper
     // session storage handler is used
     if (!$this->getContainer()->getParameter('bzion.features.websocket.enabled')) {
         $message = "You need to enable websockets in your config before using the push server";
         $output->writeln("<bg=red;options=bold>\n\n [ERROR] {$message}\n</>");
         return;
     }
     $loop = EventLoopFactory::create();
     $pusher = new EventPusher($loop, $output);
     $pushPort = $input->getOption('push') ?: $this->getContainer()->getParameter('bzion.features.websocket.push_port');
     $pullPort = $input->getOption('pull') ?: $this->getContainer()->getParameter('bzion.features.websocket.pull_port');
     $pullSocket = new Server($loop);
     $pullSocket->on('connection', function ($conn) use($pusher) {
         $conn->on('data', function ($data) use($pusher) {
             $pusher->onServerEvent(json_decode($data));
         });
     });
     // Bind to 127.0.0.1, so that only the server can send messages to the socket
     $pullSocket->listen($pullPort, '127.0.0.1');
     $output->writeln(" <fg=green>Running pull service on port {$pullPort}</>");
     $session = new SessionProvider($pusher, new DatabaseSessionHandler());
     $pushSocket = new Server($loop);
     $webServer = new IoServer(new WsServer($session), $pushSocket);
     // Binding to 0.0.0.0 means remotes can connect
     $pushSocket->listen($pushPort, '0.0.0.0');
     $output->writeln(" <fg=green>Running push service on port {$pushPort}</>");
     $output->writeln("\n <bg=green;options=bold>Welcome to the BZiON live notification server!</>");
     $loop->run();
 }
开发者ID:blast007,项目名称:bzion,代码行数:31,代码来源:ServerCommand.php

示例10: __construct

 /**
  * Constructor
  *
  * @param OutputInterface $output  Output
  * @param string          $docroot Docroot
  * @param string          $env     Environment
  * @param bool            $debug   Debug
  * @param int             $port    Port
  */
 public function __construct(OutputInterface $output, $docroot, $env, $debug, $port = null)
 {
     $repository = new PhpRepository();
     if (!$port) {
         $port = 8000;
     }
     $this->output = $output;
     $this->env = $env;
     $this->debug = $debug;
     $this->port = $port;
     $this->loop = new StreamSelectLoop();
     $socketServer = new ReactSocketServer($this->loop);
     $httpServer = new ReactHttpServer($socketServer);
     $httpServer->on("request", function ($request, $response) use($repository, $docroot, $output) {
         $path = $docroot . '/' . ltrim(rawurldecode($request->getPath()), '/');
         if (is_dir($path)) {
             $path .= '/index.html';
         }
         if (!file_exists($path)) {
             HttpServer::logRequest($output, 404, $request);
             $response->writeHead(404, ['Content-Type' => 'text/html']);
             return $response->end(implode('', ['<h1>404</h1>', '<h2>Not Found</h2>', '<p>', 'The embedded <a href="https://sculpin.io">Sculpin</a> web server could not find the requested resource.', '</p>']));
         }
         $type = 'application/octet-stream';
         if ('' !== ($extension = pathinfo($path, PATHINFO_EXTENSION))) {
             if ($guessedType = $repository->findType($extension)) {
                 $type = $guessedType;
             }
         }
         HttpServer::logRequest($output, 200, $request);
         $response->writeHead(200, array("Content-Type" => $type));
         $response->end(file_get_contents($path));
     });
     $socketServer->listen($port, '0.0.0.0');
 }
开发者ID:georgjaehnig,项目名称:sculpin,代码行数:44,代码来源:HttpServer.php

示例11: setUpWebSocket

 /**
  * Set up our WebSocket server for clients wanting real-time updates
  *
  * @param StreamSelectLoop $loop
  * @return Ratchet\Server\IoServer
  */
 protected function setUpWebSocket(StreamSelectLoop $loop)
 {
     $webSock = new Server($loop);
     // Binding to 0.0.0.0 means remotes can connect
     $webSock->listen(static::SERVER_PORT, '0.0.0.0');
     return new IoServer(new HttpServer(new WsServer(new WampServer($this->pusher))), $webSock);
 }
开发者ID:admsa,项目名称:larachet,代码行数:13,代码来源:PushServer.php

示例12: setupWebSocketServer

 /**
  * Setup the web socket server.
  *
  * @param $loop
  * @throws \React\Socket\ConnectionException
  */
 protected function setupWebSocketServer($loop)
 {
     $webSock = new Server($loop);
     $webSock->listen(Config::get('socket.socketPort', 8080), '0.0.0.0');
     $webServer = new IoServer(new HttpServer(new WsServer(new WampServer($this->socketServer))), $webSock);
     $this->info(sprintf('Server listening at 0.0.0.0:%s', Config::get('socket.socketPort', 8080)));
 }
开发者ID:xintang22,项目名称:Paxifi,代码行数:13,代码来源:ListenCommand.php

示例13: initHttpServer

 private function initHttpServer()
 {
     $socket = new ServerSocket($this->getLoop());
     $socket->listen($this->config->getPort(), $this->config->getHost());
     $http = new HttpServer($socket, $this->getLoop());
     $http->on('request', [$this, 'handleRequest']);
 }
开发者ID:unclead,项目名称:php-cluster,代码行数:7,代码来源:Application.php

示例14: assertConnection

 public function assertConnection(array $options, $message = null)
 {
     $settings = array_merge(["ip" => "0.0.0.0", "port" => 0, "startServer" => false, "match" => true], $options);
     // optionally starting server
     if ($settings["startServer"]) {
         $serverLoop = EventLoopFactory::create();
         $server = new SocketServer($serverLoop);
         $server->listen($settings["port"]);
     }
     // client setup
     $clientLoop = EventLoopFactory::create();
     $dnsResolverFactory = new DnsResolverFactory();
     $dns = $dnsResolverFactory->createCached("8.8.8.8", $clientLoop);
     // dunno why dns is required for this shit
     $connector = new SocketConnector($clientLoop, $dns);
     $promise = $connector->create($settings["ip"], $settings["port"])->then(function (SocketStream $stream) {
         $stream->close();
         return true;
     }, function (SocketConnectionException $e) {
         return false;
     });
     $clientLoop->run();
     // catching the output
     $out = null;
     $promise->done(function ($v) use(&$out) {
         $out = $v;
     });
     // optionally cleaning up the server
     if ($settings["startServer"]) {
         $server->shutdown();
     }
     $this->assertEquals($out, $settings["match"], $message);
 }
开发者ID:ihsw,项目名称:toxiproxy-php-client,代码行数:33,代码来源:AbstractTest.php

示例15: startTransportProvider

 /**
  * Start transport provider
  *
  * @param \Thruway\Peer\AbstractPeer $peer
  * @param \React\EventLoop\LoopInterface $loop
  */
 public function startTransportProvider(AbstractPeer $peer, LoopInterface $loop)
 {
     $this->peer = $peer;
     $this->loop = $loop;
     $socket = new Server($loop);
     $socket->on('connection', [$this, "handleConnection"]);
     $socket->listen($this->port, $this->address);
 }
开发者ID:pacho104,项目名称:redbpim,代码行数:14,代码来源:RawSocketTransportProvider.php


注:本文中的React\Socket\Server类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。