The problem is, when the client sends it's first message after getting a message, it can no longer receive and reply with a message.
Here is the code:
public void demo() {
try {
client = new MqttClient("tcp://broker:1883", "Sending");
client.connect();
client.setCallback(this);
client.subscribe("receive");
} catch (MqttException e) {}
}
@Override
public void messageArrived(String topic, MqttMessage message)
throws Exception {
message.setPayload("I'm replying".getBytes());
client.publish("publish", message);
}
I have something similar in Android development and it works as a charm. Paho 3-1.0.2