B4J Question [SOLVED] B4A + B4J + B4XSerializator (in class module) problem

rosippc64a

Active Member
Licensed User
Longtime User
Hi All!
I used the b4xserializator with success between b4a and b4j, while there was only one connection. But I wanted rewrite my program to multiple connection, so I follow @Erel example CCTV.
In my case the B4A send data to B4j, where I got error (in b4j):
B4X:
client._astream_newdata (java line: 51)
java.util.zip.ZipException: incorrect header check
    at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164)
...
I have the usual type
B4X:
'B4A LSZAMLAv3.b4a (Main)
Sub Process_Globals
    ...
    Type MyMessage (Command As String, Timestamp As String, xml As String)
End Sub
'B4J lszamlakomm.b4j (Main)
Sub Process_Globals
    Type MyMessage (Command As String, Timestamp As String, xml As String)
    ...
End Sub
The line, where the error happen looks like (client.bas, b4j):
B4X:
Private Sub AStream_NewData (Buffer() As Byte)
    Dim mm As MyMessage = ser.ConvertBytesToObject(Buffer) '<---- error
I feel that this error happened only because this sub moved from main code module to client class module (in B4J).
What is the right approach using b4xserializator with structure in class?
thanks
Steven
 
Last edited:

rosippc64a

Active Member
Licensed User
Longtime User
I forgot mention, the type declaration is in the Main module (both b4a and b4j). Only the AStream_NewData in in the class.
 
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
Thank you @Erel , here is the error message:
B4X:
Waiting for debugger to connect...
Program started.
Init colors
Read color settings map...
before: Wait For(initdb)
Initdb
before: wait for PostgreSQL_Ready
after: wait for PostgreSQL_Ready
DBVersion = 47
after: Wait For(initdb)
Init:
UDP initialize
UDP service start. ip: 192.168.0.155 port: 51041
New connection
Error occurred on line: 15 (Client)
java.util.zip.ZipException: incorrect header check
    at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164)
    at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:122)
    at java.io.DataInputStream.readByte(DataInputStream.java:265)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readByte(B4XSerializator.java:150)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readObject(B4XSerializator.java:318)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.ReadObject(B4XSerializator.java:129)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.ConvertBytesToObject(B4XSerializator.java:99)
    at b4j.leiszamla.komm.client._astream_newdata(client.java:72)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at sun.reflect.GeneratedMethodAccessor8.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA$2.run(BA.java:230)
    at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
    at java.lang.Thread.run(Thread.java:748)
The 15. line is:
B4X:
Private Sub AStream_NewData (Buffer() As Byte)
    Dim mm As MyMessage = ser.ConvertBytesToObject(Buffer) '<--- 15. line
 
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
Yes, you are right. Here is the sender initialization code:
B4X:
    Log("Trying to connect to: " & Host)
    CloseExistingConnection
    Dim client As Socket
    client.Initialize("client")
    client.Connect(Host, PORT, 10000)
    Wait For Client_Connected (Successful As Boolean)
    If Successful Then
        astream.InitializePrefix(client.InputStream, False, client.OutputStream, "astream")
        UpdateState (True)
        Dim mm As MyMessage
        mm.Initialize
        mm.Command = "STARTKOMM"
        mm.Timestamp = $"$DateTime{DateTime.Now}"$
        mm.xml = ""
        CallSub2(adatFriss, "NewData", ser.ConvertObjectToBytes(mm))
    Else
        Log("Failed to connect: " & LastException)
    End If
But it is strange that until the receiver code resided in the b4j main module, this code was successful.
 
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
I used this linked code first time and it worked well, but it was only for one connection at the same time, but I need multiple connection, so I moved to your CCTV code what provide multiple connection, but there the b4xserializator failed (because the serializator is in a class - as I experienced).
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…