Skip to content

Commit

Permalink
Uncaught TypeError: strlen() expects parameter 1 to be string
Browse files Browse the repository at this point in the history
  • Loading branch information
addls committed Sep 20, 2020
1 parent 0f91412 commit 1fd431a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Client/MQTTClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* @document https://doc.simps.io
* @license https://github.com/simple-swoole/simps/blob/master/LICENSE
*/

namespace Simps\Client;

use Simps\Exception\Protocol\MQTTException;
Expand Down Expand Up @@ -41,10 +42,10 @@ public function __construct(array $config, array $swConfig = [])
{
$this->config = array_replace_recursive($this->config, $config);
$this->client = new Client(SWOOLE_SOCK_TCP);
if (! empty($swConfig)) {
if (!empty($swConfig)) {
$this->client->set($swConfig);
}
if (! $this->client->connect($this->config['host'], $this->config['port'], $this->config['time_out'])) {
if (!$this->client->connect($this->config['host'], $this->config['port'], $this->config['time_out'])) {
//尝试重连
$this->reConnect();
}
Expand Down Expand Up @@ -73,7 +74,7 @@ public function connect(bool $clean = true, array $will = [])
if (isset($this->config['password'])) {
$data['password'] = $this->config['password'];
}
if (! empty($will)) {
if (!empty($will)) {
$data['will'] = $will;
}
return $this->sendBuffer($data);
Expand Down Expand Up @@ -139,11 +140,12 @@ public function publish($topic, $content, $qos = 0, $dup = 0, $retain = 0)
* 接收订阅的消息.
*
* @return array|bool|string
* @throws MQTTException
*/
public function recv()
{
$response = $this->client->recv();
if (strlen($response) > 0) {
if (is_string($response) && strlen($response) > 0) {
return MQTT::decode($response);
}
if ($response === '') {
Expand Down Expand Up @@ -216,7 +218,7 @@ private function reConnect()
{
$reConnectTime = 1;
$result = false;
while (! $result) {
while (!$result) {
Coroutine::sleep(3);
$this->client->close();
$result = $this->client->connect($this->config['host'], $this->config['port'], $this->config['time_out']);
Expand Down

0 comments on commit 1fd431a

Please sign in to comment.