java - Eclipse Paho - MQTT client connected to localhost always disconnected due to Null Pointer Exeception after receiving a message -


i initializing mqtt client on web server should connected long server running. running mqtt broker (emq) on same machine. so, mqtt client connect localhost.

here's code connecting client:

string topic_clients = "$sys/brokers/nodename/clients/"; string clientid = "server_sub" + "_" + system.currenttimemillis(); int qos_level = 2  connectoptions = new mqttconnectoptions(); connectoptions.setcleansession(true); connectoptions.setusername(clientid);  try  {     subclient = new mqttclient("tcp://127.0.0.1:1883", clientid, new memorypersistence());     subclient.setcallback(callback);      subclient.connect(connectoptions);     subclient.subscribe(new string[]{"#", topic_clients + "+/connected", topic_clients + "+/disconnected"}, new int[]{qos_level, qos_level, qos_level}); }   catch (mqttexception e)  {     e.printstacktrace(); } 

this callback:

private mqttcallback callback = new mqttcallback()  {     @override     public void connectionlost(throwable cause)      {         system.out.println("mqttpublisher - connection lost cause:" + cause.tostring());     }      @override     public void messagearrived(string topic, mqttmessage message) throws exception      {         system.out.println("mqttpublisher - message arrived topic:" + topic + " message:" + message);     }      @override     public void deliverycomplete(imqttdeliverytoken token)      {         system.out.println("mqttpublisher - delivery completed");     } }; 

this method public void connectionlost(throwable cause) called after method public void messagearrived(string topic, mqttmessage message) throws exception called.

the cause is:

deviceinfosubscriber - connection lost cause:mqttexception (0) - java.lang.nullpointerexception 

then, when try reconnect broker, time reconnection took 10s.

what possible reason this?


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -