示例#1
0
 /**
  * @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);
     }
 }
示例#2
0
文件: App.php 项目: perfect-coin/chat
 /**
  * @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)
 {
     if (extension_loaded('xdebug')) {
         echo "XDebug extension detected. Remember to disable this if performance testing or going live!\n";
     }
     if (null === $loop) {
         $loop = LoopFactory::create();
     }
     $this->httpHost = $httpHost;
     $socket = new Reactor($loop);
     $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();
     $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);
     }
 }
示例#3
0
 /**
  * Allow Flash sockets to connect to our server.
  * For this we have to listen on flash.port (843) and return
  * the flashpolicy
  *
  * @return void
  */
 protected function allowFlash()
 {
     $flashSock = new ReactServer($this->loop);
     $flashSock->listen($this->option('flash-port'), self::IP);
     $policy = new FlashPolicy();
     $policy->addAllowedAccess('*', $this->option('port'));
     $webServer = new IoServer($policy, $flashSock);
     $this->info('Flash connections allowed with policy on port <comment>[' . $this->option('flash-port') . ']</comment>', 1);
 }
示例#4
0
// Setup logging
$stdout = new StreamHandler('php://stdout');
$logout = new Logger('SockOut');
$login = new Logger('Sock-In');
$login->pushHandler($stdout);
$logout->pushHandler($stdout);
// The all mighty event loop
$loop = Factory::create();
// This little thing is to check for connectivity...
// As a case study, when people connect on port 80, we're having them
//  also connect on port 9000 and increment a counter if they connect.
// Later, we can publish the results and find out if WebSockets over
//  a port other than 80 is viable (theory is blocked by firewalls).
$context = new Context($loop);
$push = $context->getSocket(ZMQ::SOCKET_PUSH);
$push->connect('tcp://127.0.0.1:5555');
// Setup our Ratchet ChatRoom application
$webSock = new Reactor($loop);
$webSock->listen(80, '0.0.0.0');
$webServer = new IoServer(new WsServer(new PortLogger($push, 80, new MessageLogger(new ServerProtocol(new Bot(new ChatRoom())), $login, $logout))), $webSock);
// Allow Flash sockets (Internet Explorer) to connect to our app
$flashSock = new Reactor($loop);
$flashSock->listen(843, '0.0.0.0');
$policy = new FlashPolicy();
$policy->addAllowedAccess('*', 80);
$webServer = new IoServer($policy, $flashSock);
$logSock = new Reactor($loop);
$logSock->listen(9000, '0.0.0.0');
$zLogger = new IoServer(new WsServer(new PortLogger($push, 9000, new NullComponent())), $logSock);
// GO GO GO!
$loop->run();