Android Question MQTT Chat Sample Crashing

eds1234

Member
Licensed User
Hi.

MQTT Chat sample is working fine with android to android, both running Chat sample.
But when I tried to publish message from my mac terminal, Chat sample crashes.

here is the command is sent from my terminal:
B4X:
mosquitto_pub -d -h 192.168.1.19 -p 9000 -t all/connect -m "mac"
192.168.1.19:9000 are from B4A Chat sample running server
any message I send to topic "all/connect" from terminal crashes the Chat sample

here is the the error log
B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Connected: true
all/connect: j5
** Activity (main) Pause, UserClosed = false **
** Activity (chat) Create, isFirst = true **
** Activity (chat) Resume **
Error occurred on line: 61 (Starter)
java.io.IOException
   at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:177)
   at libcore.io.Streams.readSingleByte(Streams.java:41)
   at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:130)
   at java.io.DataInputStream.readByte(DataInputStream.java:75)
   at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readByte(B4XSerializator.java:133)
   at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readObject(B4XSerializator.java:301)
   at anywheresoftware.b4a.randomaccessfile.B4XSerializator.ReadObject(B4XSerializator.java:112)
   at anywheresoftware.b4a.randomaccessfile.B4XSerializator.ConvertBytesToObject(B4XSerializator.java:82)
   at b4a.example.starter._client_messagearrived(starter.java:283)
   at java.lang.reflect.Method.invoke(Native Method)
   at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
   at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
   at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
   at java.lang.reflect.Method.invoke(Native Method)
   at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
   at anywheresoftware.b4a.BA$2.run(BA.java:370)
   at android.os.Handler.handleCallback(Handler.java:739)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   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.util.zip.DataFormatException: incorrect header check
   at java.util.zip.Inflater.inflateImpl(Native Method)
   at java.util.zip.Inflater.inflate(Inflater.java:237)
   at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:158)
   ... 22 more

Please help to resolve. Thank you.
 
Last edited:

eds1234

Member
Licensed User
Thanks for the response Erel.

I tried compressing Client_MessageArrived sub to this:
B4X:
Private Sub client_MessageArrived (Topic As String, Payload() As Byte)
   Dim receivedObject As Object = serializator.ConvertBytesToObject(Payload)
   Dim newMsg As String = receivedObject
   Log($"${Topic}: ${newMsg}"$)
End Sub

but there is still error and the application crashed.

here is the error log
B4X:
Error occurred on line: 65 (Starter)
java.util.zip.ZipException: incorrect header check
   at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:175)
   at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:127)
   at java.io.DataInputStream.readByte(DataInputStream.java:268)
   at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readByte(B4XSerializator.java:133)
   at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readObject(B4XSerializator.java:301)
   at anywheresoftware.b4a.randomaccessfile.B4XSerializator.ReadObject(B4XSerializator.java:112)
   at anywheresoftware.b4a.randomaccessfile.B4XSerializator.ConvertBytesToObject(B4XSerializator.java:82)
   at java.lang.reflect.Method.invoke(Native Method)
   at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
   at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
   at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
   at java.lang.reflect.Method.invoke(Native Method)
   at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
   at anywheresoftware.b4a.BA$2.run(BA.java:370)
   at android.os.Handler.handleCallback(Handler.java:873)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:214)
   at android.app.ActivityThread.main(ActivityThread.java:7094)
   at java.lang.reflect.Method.invoke(Native Method)
   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)

Yes, just want to send a simple text message.
 
Upvote 0

eds1234

Member
Licensed User
Hi Erel, a simple PubSub string is working now, with this:

B4X:
Private Sub client_Connected (Success As Boolean)
   If Success Then
       'connected = True
       'client.Subscribe("all/#", 0)
       Dim s As String = "abc"
       Dim b() As Byte = s.GetBytes("UTF8")
       client.Publish("all/connect", b)
       'Log($"Connected: ${Success}"$)
       ToastMessageShow("Connected to Server",True)
   Else
       ToastMessageShow("Error connecting: " & LastException, True)
   End If
End Sub

Private Sub client_MessageArrived (Topic As String, Payload() As Byte)
   Dim newMsg As String = BytesToString(Payload, 0, Payload.Length, "UTF8")
   Log($"${Topic}: ${newMsg}"$)
End Sub

Got the the conversion from: https://www.b4x.com/android/forum/threads/b4x-text-strings-and-parsers.83510/#content.

Though still interested to learn the format of B4XSerializator.

Thank you.
 
Upvote 0
Top