java - MQTT - subscribe method is not working -


i have mqtt ckient app working on, publish method working fine having hard time subscribe method.

this subscribe method, suppose click button subcribe topic:

 public void subscribe( mqttclient mc) {   string topic = jtextfield3.gettext();  int qos = jcombobox1.getselectedindex() ;   string[] topics = {topic};   int[] qos = {qos};   if ( jlabel3.gettext().equals("connected") ) {      try {      mc.subscribe( topics, qos );            system.out.println(topics +"    "+qos);                  system.out.println(topic +"    "+qos);             jbutton2.settext("subscribed");             jtextfield4.settext(topics.tostring());          } catch ( exception ex ) {    joptionpane.showmessagedialog( this, ex.getmessage(),      "mqtt subscription exception", joptionpane.error_message );         }        } else {     jtextarea1.settext("not connected");     }        }    

this actionperformed method button

 private void jbutton2actionperformed(java.awt.event.actionevent evt) {                                              subscribe(mc); 

}

this publishedarrived method:

  public void publisharrived( string topic, byte[] data, int qos, boolean        retained ) {     jtextfield4.settext(topic);    string msgdata = new string(data);   jtextarea1.settext(new string(data));     } 

someone should please me out here.

you need implement callback , message arrived function. function handle message. see paho mqtt message client example in here subscribe , read mqtt message using paho


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -