Android Question MQTT client connection problems 32104

rboeck

Well-Known Member
Licensed User
Longtime User
Hi, i am currently testing communication between two android devices and i receive randomly this 3104 errror
(no connection to client at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:31)).

I made an directory to store these outgoing messages, and want send them later. But i want to know, what the best setup for mqtt communiction is: should i always open and close the connection to avoid this errors, maybe with a service or should i look for another provider? My communiction is two way, i want to have synched two sqlite databases with the help of mqtt.
 

rboeck

Well-Known Member
Licensed User
Longtime User
No, i use
B4X:
try
   MQTT.Publish2(...)
catch
   File.Write...   for unsent message
end try
construct and the program flow goes to the catch statement. In the log view i find the error message. I have no disconnected event - should i have one?
I use a different client id on all devices. Currently i am sending all messages with QOS2. Should i receive each message on each client only one time?
 
Upvote 0

rboeck

Well-Known Member
Licensed User
Longtime User
After a longer time i the app crashes, when i publish a message.

So i have a further question: Currently i have a public mqtt in process_globals of a code module. I am using the mqtt from tree other activities. Where to i have to have the events - in the code module, in which mqtt is declared or in the mostly used activity? Or is it better to create a service for mqtt?
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
i have a public mqtt in process_globals of a code module
Code modules dont receive any events. Codemodules can be used to hold static methods.
If you need to handle Events then you should use a CLASS or a SERVICE or even a Activity.

The best place is to place it in starter service including all needed eventsubs
 
Upvote 0

rboeck

Well-Known Member
Licensed User
Longtime User
I changed my app to hande the Diconnected event - but the problem was much bigger then before: each disconnect event leaded to a complete restart of the app and because the disconnected event is inside a service it is much harder to find and to debug.
From the log file: Unable to create service at at.rb.xxx.xxx.starter: java.lang.runtimeException: java.io.EOFException at android.appp.ActivityThread.handleCreateService( ActivityThread.java:3820)
The strange thing was, that it was a different behaviour between different types of tablets. On sony i had no problem, on samsung i had most of the problems.

Now my question: is this normal behaviour that a simple connection problem seems to crash my app? In this case it is easier for me to make an indepent watch of internet connection and as long as i am debugging, i try to use the code inside a activity module?

My second question: i use an subscription and wait all the day for messages. Would it be a better app design to be disconnect most of the time and only check 5 times in an hour because of energy use or is this optimized automaticly?
 
Last edited:
Upvote 0

rboeck

Well-Known Member
Licensed User
Longtime User
Thats what i could find:

Killing previous instance (adressliste).

java.lang.RuntimeException: Unable to create service at.rb.b4a.gmap1.starter: java.lang.RuntimeException: java.io.EOFException
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3820)
at android.app.ActivityThread.access$2100(ActivityThread.java:223)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1885)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7231)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.RuntimeException: java.io.EOFException
at anywheresoftware.b4a.shell.Shell.virtualAssets(Shell.java:168)
at anywheresoftware.b4a.shell.Shell.start(Shell.java:100)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:88)
at at.rb.b4a.gmap1.starter.onCreate(starter.java:32)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3810)
... 8 more
Caused by: java.io.EOFException
at libcore.io.Streams.readFully(Streams.java:83)
at java.io.DataInputStream.readInt(DataInputStream.java:103)
at anywheresoftware.b4a.shell.Shell.virtualAssets(Shell.java:140)
... 12 more
 
Upvote 0
Top