我是PHP世界的新手,在连接到MQTT时遇到了问题。
我使用的是phpMQTT.php库,我使用IP地址连接到MQTT。我试图发布到MQTT,获取phpMQTT.php库文件中的错误
错误是: tcp://.__..*:8083 stream_socket_client():无法连接到(连接超时)
在以下代码中面临的问题:
if ($this->cafile) {
$socketContext = stream_context_create(["ssl" => [
"verify_peer_name" => true,
"cafile" => $this->cafile
]]);
$this->socket = stream_socket_client("tls://" . $this->address . ":" . $this->port, $errno, $errstr, 60, STREAM_CLIENT_CONNECT, $socketContext);
} else {
$this->socket = stream_socket_client("tcp://" . $this->address . ":" . $this->port, $errno, $errstr, 60, STREAM_CLIENT_CONNECT);
}发布于 2020-04-12 18:08:37
来自phpMQTT.php库
(来源于https://github.com/bluerhinos/phpMQTT/blob/master/phpMQTT.php ),
您必须设置以下详细信息,如源代码所示。
/* sets the broker details */
function broker($address, $port, $clientid, $cafile = NULL){
$this->address = $address;
$this->port = $port;
$this->clientid = $clientid;
$this->cafile = $cafile;
}如果您有一个防火墙运行-做打开您正在使用的端口以及。
https://stackoverflow.com/questions/61175278
复制相似问题