Esempio n. 1
0
 public function publish(Stream $stream, $topic, $message, $qos = 0, $dup = false)
 {
     $deferred = new Deferred();
     $packet = new Publish($this->version);
     $packet->setTopic($topic);
     $packet->setMessageId($this->messageCounter++);
     $packet->setQos($qos);
     $packet->setDup($dup);
     $packet->addRawToPayLoad($message);
     $success = $this->sentMessageToStream($stream, $packet);
     if ($success) {
         $deferred->resolve($stream);
     } else {
         $deferred->reject();
     }
     return $deferred->promise();
 }
Esempio n. 2
0
 public function testParseWithDup()
 {
     $input = chr(56) . chr(4) . chr(0) . chr(0) . chr(0) . chr(10);
     $version = new \oliverlorenz\reactphpmqtt\protocol\Version4();
     $parsedPacket = \oliverlorenz\reactphpmqtt\packet\Publish::parse($version, $input);
     $comparisonPacket = new \oliverlorenz\reactphpmqtt\packet\Publish($version);
     $comparisonPacket->setDup(true);
     $this->assertEquals(\oliverlorenz\reactphpmqtt\packet\MessageHelper::getReadableByRawString($parsedPacket->get()), \oliverlorenz\reactphpmqtt\packet\MessageHelper::getReadableByRawString($comparisonPacket->get()));
 }