Ejemplo n.º 1
0
 /**
  * Run WebSocket Server
  *
  * Usage (from command line):
  * 
  * php oil r ratchet:wamp <class_name>
  * 
  * Note:
  * http://socketo.me/docs/push
  * http://socketo.me/docs/wamp
  */
 public static function wamp($class_name = null)
 {
     /**
      * Check class name
      */
     if (!class_exists($class_name)) {
         static::help();
         exit;
     }
     $config = \Ratchet::get_config($class_name);
     /**
      * Check port
      */
     if (!is_numeric($config['port'])) {
         static::help();
         exit;
     }
     /**
      * Check zmq port
      */
     if (!is_numeric($config['zmq_port'])) {
         static::help();
         exit;
     }
     $loop = \React\EventLoop\Factory::create();
     $class = new $class_name();
     /**
      * Listen for the web server to make a ZeroMQ push after an ajax request
      */
     $context = new \React\ZMQ\Context($loop);
     $pull = $context->getSocket(\ZMQ::SOCKET_PULL);
     // Binding to 127.0.0.1 means the only client that can connect is itself
     $pull->bind('tcp://127.0.0.1:' . $config['zmq_port']);
     $pull->on('message', array($class, 'zmqCallback'));
     /**
      * Set up our WebSocket server for clients wanting real-time updates
      */
     $socket = new \React\Socket\Server($loop);
     // Binding to 0.0.0.0 means remotes can connect
     $socket->listen($config['port'], '0.0.0.0');
     $server = new \Ratchet\Server\IoServer(new \Ratchet\WebSocket\WsServer(new \Ratchet\Wamp\WampServer($class)), $socket);
     $loop->run();
 }
Ejemplo n.º 2
0
 public function onOpen(\Ratchet\ConnectionInterface $conn)
 {
     $conn->session = Ratchet::get_session($conn);
 }