当我尝试通过此 JS 连接到 Mosquitto 服务器时,收到此错误:
WebSocket connection to 'ws://xx.xxx.xxx.xxx:1883/mqtt' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET
Run Code Online (Sandbox Code Playgroud)
我从控制台尝试过,它工作正常。我尝试使用 Java 客户端作为提供者和消费者,它工作正常。所以我无法理解我该怎么做才能让它工作。
这是JS:
client = new Paho.MQTT.Client("xx.xxx.xxx.xxx", 1883, "clientId");
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;
// connect the client
client.connect({onSuccess:onConnect});
Run Code Online (Sandbox Code Playgroud)
这是 Java(工作):
@Stateless
@LocalBean
public class PahoManager implements MqttCallback {
MqttClient client;
public void init() {
try {
client = new MqttClient("tcp://192.168.50.10:1883", "pahomqttpublish1");
client.connect();
client.subscribe("pahodemo/test");
} catch (MqttException e) {
e.printStackTrace();
}
}
public void doDemo() {
try {
MqttMessage message = new MqttMessage(); …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Windows 上配置 Mosquitto MQTT 代理,并使用用户名和密码进行身份验证。
我在 mosquitto.conf 文件中添加了以下行:
允许匿名假
用户名测试remote_username测试
远程密码测试123
运行代理时出现以下错误:
C:\Program Files (x86)\mosquitto>mosquitto.exe -c mosquitto.conf -p 1883 错误:桥接配置无效。在 mosquitto.conf 发现错误:750。错误:无法打开配置文件。
无需用户名和密码,我就可以启动代理并与 MQTTLens 客户端连接。
谢谢,阿肖克
我面临特定 client_id 断开连接的问题。当我尝试连接时,它会突然断开连接并显示错误
1450599983: New connection from 192.168.2.245 on port 1883.
1450599983: Client 46144 disconnected.
1450599983: New client connected from 192.168.2.245 as 46144 (c0, k60).
1450599984: Socket error on client 46144, disconnecting.
Run Code Online (Sandbox Code Playgroud)
我的conf.d文件是
# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example
pid_file /var/run/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /var/log/mosquitto/mosquitto.log
include_dir /etc/mosquitto/conf.d
cleansession true
Run Code Online (Sandbox Code Playgroud)
有时会在发送消息后发生。为什么会发生这种情况,我们该如何解决这个问题?
谢谢
我在 EC2 上的 Ubuntu 上运行 mosquitto 代理。我也做了一个改变max_queued_messages 1000,max_inflight_messages 10在/etc/mosquitto/mosquitto.conf
我使用qos=2发布到这个代理并保留 enabled。对于发布,我使用mosquitto_pub -t 1 -m "{c:{d:\"pN\",m:\"Pr1\"}}" -r -q 2. 订阅者方面我正在使用 org.eclipse.paho.android.service:1.0.2具有相同 qos=2 的库。
并且仅通过options.setMqttVersion(MqttConnectOptions.MQTT_VERSION_3_1)for 参数提供单个选项client.connect(options)。
如果连接到服务器的订阅者设备由于任何原因断开连接并再次重新连接,那么问题就来了,然后只获得最后一条保留的消息,而缺少消息之间的所有内容。
而且,即使尚未发布任何内容,重新连接后仍会获取订阅者设备在断开连接之前可能已经获得的最后保留消息。
我希望在重新连接订阅者后应该获得在断开连接期间发布的所有消息,如果已经获得,则不应再次显示。想知道如何以及在哪里做。
当尝试连接到本地运行的 Mosquitto MQTT 队列时,出现以下错误。
Unhandled exception. System.AggregateException: One or more errors occurred. (The client has been disconnected while trying to perform the connection)
---> System.Net.Mqtt.MqttClientException: The client has been disconnected while trying to perform the connection
at System.Net.Mqtt.Sdk.MqttClientImpl.ConnectAsync(MqttClientCredentials credentials, MqttLastWill will, Boolean cleanSession)
Run Code Online (Sandbox Code Playgroud)
我在设置时使用默认选项System.Net.Mqtt.MqttClient。
Unhandled exception. System.AggregateException: One or more errors occurred. (The client has been disconnected while trying to perform the connection)
---> System.Net.Mqtt.MqttClientException: The client has been disconnected while trying to perform the connection
at System.Net.Mqtt.Sdk.MqttClientImpl.ConnectAsync(MqttClientCredentials …Run Code Online (Sandbox Code Playgroud)