Java and MQTT Broker

0

I'm learning to mess with broker and I'm trying to connect my java program to the online broker of shiftr.io and it's returning:

Exception in thread "main" O cliente não está conectado (32104)
    at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:31)
    at org.eclipse.paho.client.mqttv3.internal.ClientComms.sendNoWait(ClientComms.java:143)
    at org.eclipse.paho.client.mqttv3.MqttAsyncClient.subscribe(MqttAsyncClient.java:721)
    at org.eclipse.paho.client.mqttv3.MqttClient.subscribe(MqttClient.java:320)
    at org.eclipse.paho.client.mqttv3.MqttClient.subscribe(MqttClient.java:295)
    at Broker.main(Broker.java:11)

I do not understand what's going wrong, Code:

import org.eclipse.paho.client.mqttv3.*;
public class Broker {

public static MqttClient client;
public static String msg = "ola mundo";

public static void main(String[] args) throws MqttException {

client = new MqttClient("tcp://broker.shiftr.io:1883", "Esp-12E-Clock");
MqttMessage message = new MqttMessage(msg.getBytes());
client.publish("/hello", message);

}
}
    
asked by anonymous 10.02.2018 / 23:11

0 answers