Skip to content

Commit 79b3b99

Browse files
authored
Fix: Send PUBREL in response to PUBREC (#37)
1 parent 289fa18 commit 79b3b99

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

.phpcs.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
<description>php-mqtt Code Style Standard</description>
44

55
<rule ref="PSR1"/>
6+
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
7+
<exclude-pattern>tests/*</exclude-pattern>
8+
</rule>
69
<rule ref="PSR2">
710
<exclude name="PSR2.Methods.MethodDeclaration.AbstractAfterVisibility"/>
811
<exclude name="Squiz.ControlStructures.ControlSignature.SpaceAfterCloseParenthesis"/>

src/MQTTClient.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,8 @@ protected function handlePublishReceipt(string $buffer): void
991991
'The MQTT broker sent a receipt for a publish that has not been pending anymore.'
992992
);
993993
}
994+
995+
$this->sendPublishRelease($messageId);
994996
}
995997

996998
/**
@@ -1272,6 +1274,23 @@ protected function sendPublishReceived(int $messageId): void
12721274
$this->writeToSocket(chr(0x50) . chr(0x02) . $this->encodeMessageId($messageId));
12731275
}
12741276

1277+
/**
1278+
* Sends a publish release message for the given message identifier.
1279+
*
1280+
* @param int $messageId
1281+
* @return void
1282+
* @throws DataTransferException
1283+
*/
1284+
protected function sendPublishRelease(int $messageId): void
1285+
{
1286+
$this->logger->debug('Sending publish release message to an MQTT broker.', [
1287+
'broker' => sprintf('%s:%s', $this->host, $this->port),
1288+
'message_id' => $messageId,
1289+
]);
1290+
1291+
$this->writeToSocket(chr(0x62) . chr(0x02) . $this->encodeMessageId($messageId));
1292+
}
1293+
12751294
/**
12761295
* Sends a publish complete message for the given message identifier.
12771296
*

0 commit comments

Comments
 (0)