Java client cannot receive messages from Mosquitto on Android

  • My Os is Windows 7,32bit.

  • I am installing the mosquitto-1.1.2-install-win32.exe file.

  • I am not modifying the file mosquitto.conf

    so there is no theme prefix.

  • Use Mosquitto to subscribe to a topic (subscription window):

    mosquitto_sub.exe -q 2 -t mytopic
    OR mosquitto_sub.exe -q 2 -t # 
    
          

  • Use Mosquitto to publish a topic like (publish window):

    mosquitto_pub.exe -q 2 -t mytopic -m "hello
          

  • Then in the subscription cmd window I can get "hello"

  • I am following the Dale Lane blog and the "Android MQTT Project" to access Mosquitto.

    java client(MQTTDemo.java): 
    //i use mobile emulator
    editor.putString("broker", "10.0.2.2″); 
    editor.putString("topic", "mytopic"); 
    //or editor.putString("topic", "#"); '#' match any topic
    
          

  • I am testing connectToBroker()

    in MQTTService.java

    , the connection is fine.

  • I am posting the topic "mytopic" again using Mosquitto.

  • But finally I cannot get the message in the mobile emulator.

    Does anyone know why or any other methods?

    Thank you so much!

+3


source to share


1 answer


Depends on how the broker is configured. Within the Mosquitto broker, there are ways to specify a topic prefix for each channel. At other times, the subscription subject should be listed as general. I'm not sure if any of them are applicable in your situation, but there is an easy diagnostic and you are not describing their use, so I offer them as a starting point.

  • An easy way to tell is to simply subscribe to #

    and then watch the subject lines you receive.
  • Always have a separate subscription controlling the broker. For example, with WebSphere MQ, I use a GUI to create a subscription #

    before testing any publications. If I get the GUI post but not the app, it indicates a different problem, if I get nothing at all.


A better description of the problem will include some of this differential diagnosis. If you can, please retest and edit the question with the results.

+3


source







All Articles