File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed
Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change 1313namespace Simps \MQTT ;
1414
1515use Simps \MQTT \Config \ClientConfig ;
16+ use Simps \MQTT \Exception \ProtocolException ;
1617use Swoole \Coroutine \Http \Client ;
1718use Swoole \Http \Status ;
19+ use Swoole \WebSocket \CloseFrame ;
1820use Swoole \WebSocket \Frame ;
1921
2022class WebSocketClient extends BaseClient
@@ -96,10 +98,16 @@ public function recv()
9698 protected function getResponse ()
9799 {
98100 $ response = $ this ->getClient ()->recv ();
99- if ($ response === false ) {
101+ if ($ response === false || $ response instanceof CloseFrame ) {
100102 return false ;
101103 }
102104 if ($ response instanceof Frame) {
105+ // If any other type of data frame is received the recipient MUST close the Network Connection.
106+ if ($ response ->opcode !== WEBSOCKET_OPCODE_BINARY ) {
107+ $ this ->getClient ()->close ();
108+ throw new ProtocolException ('MQTT Control Packets MUST be sent in WebSocket binary data frames. ' );
109+ }
110+
103111 return $ response ->data ;
104112 }
105113
You can’t perform that action at this time.
0 commit comments