mqtt-users team mailing list archive
-
mqtt-users team
-
Mailing list archive
-
Message #00104
java.io.EOFException while connecting Mosquitto broker
Hi,
I am facing problems while connecting a another client to Mosquitto broker
(ver. 0.15 - 20120205) running on my system (Windows XP Sp3).
I can successfully create and connect my first client to broker.
When I try to connect second client to the broker. It throws following
exception.
MqttException (0) - java.io.EOFException
at
org.eclipse.paho.client.mqttv3.internal.wire.MqttWireMessage.createWireMessage(MqttWireMessage.java:202)
at
org.eclipse.paho.client.mqttv3.internal.wire.MqttWireMessage.createWireMessage(MqttWireMessage.java:148)
at
org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:66)
at
org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:86)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.EOFException
at java.io.DataInputStream.readFully(Unknown Source)
at java.io.DataInputStream.readUTF(Unknown Source)
at java.io.DataInputStream.readUTF(Unknown Source)
at
org.eclipse.paho.client.mqttv3.internal.wire.MqttPublish.<init>(MqttPublish.java:60)
at
org.eclipse.paho.client.mqttv3.internal.wire.MqttWireMessage.createWireMessage(MqttWireMessage.java:171)
... 4 more
/* My timeserver code, the first client for mosquitto broker */
package com.bizlers.timeserver;
import java.util.Calendar;
import java.util.Date;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.MqttTopic;
public class TimePublishTest {
private static final String SERVER_URI = "tcp://localhost:1883";
private static final String CLIENT_ID = "pub";
private MqttClient mqttClient;
public static void main(String args[]) {
new TimePublishTest().doMqttTest();
}
public void doMqttTest() {
try {
mqttClient = new MqttClient(SERVER_URI, CLIENT_ID);
mqttClient.connect();
} catch (MqttException e) {
e.printStackTrace();
}
while (true) {
Date date = Calendar.getInstance().getTime();
System.out.println(date.toString());
try {
// Get an instance of the topic
MqttTopic topic = mqttClient.getTopic("time");
MqttMessage message = new MqttMessage(date.toString()
.getBytes());
MqttDeliveryToken token = topic.publish(message);
// Wait until the message has been delivered to the server
token.waitForCompletion();
Thread.sleep(50 * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
/* My timeclient code, the second client for mosquitto broker */
package com.bizlers.timeclient;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.MqttTopic;
public class TimeSubscribeTest implements MqttCallback {
private static final String SERVER_URL = "tcp://localhost:1883"; // "tcp://
test.mosquitto.org:1883";;
private static final String CLIENT_ID = "sub1";
private MqttClient mqttClient;
public static void main(String[] args) {
new TimeSubscribeTest().test();
}
public void test() {
try {
mqttClient = new MqttClient(SERVER_URL, CLIENT_ID);
mqttClient.setCallback(this);
mqttClient.connect();
mqttClient.subscribe("time");
} catch (MqttException e) {
e.printStackTrace();
}
}
@Override
public void connectionLost(Throwable cause) {
System.out.println("Connection lost. \nCause: " + cause);
}
@Override
public void messageArrived(MqttTopic topic, MqttMessage message)
throws Exception {
System.out.println("Message arrived. \nMessage: " + message.toString());
}
@Override
public void deliveryComplete(MqttDeliveryToken token) {
System.out.println("Delivery complete. \nToken: " + token.toString());
}
}
I am using Eclipse Paho api library (paho.client.mqttv3.jar).
I am able to connect to tcp:test.mosquitto.org:1883 as well as rsmb broker
running on my system.
Am I missing something? Or do I need to setup/configure mosquitto broker?
--
Thanks and best regards,
From
Pawan D. Dalal
Follow ups