Example #1
0
 /**
  * Listen on the socket and receive a single packet.
  *
  * @param $topic Only return packets from this topic (optional)
  * @return Packet
  */
 public function receivePacket($topic = null)
 {
     $socket = $this->socket();
     while (true) {
         if ($topic && !empty($this->inbox[$topic])) {
             return array_shift($this->inbox[$topic]);
         }
         if ($socket->dataAvailable()) {
             $packet = Packet::read($socket);
             if ($topic && $packet->topic() != $topic) {
                 $this->inbox[$packet->topic()] = $packet;
                 continue;
             }
             return $packet;
         }
     }
 }
Example #2
0
 /**
  * testType method
  *
  * @return void
  */
 public function testType()
 {
     $packet = new Packet(Packet::TYPE_CONNACK);
     $this->assertSame(Packet::TYPE_CONNACK, $packet->type());
 }