Android Question B4XSerializator and AsyncStreams problem

millstone

Member
Licensed User
Longtime User
Dear all,

I have a running B4A Application and would like to extend this Application to send Files and
Text to the PC. Therefore I have made a B4J Application for the PC with the Network examples here
from the community.

In B4A I have this Type:
Type MyMessage (Kennung As String, Text1 As String,Text2 As String,MSG As String, FileTosend() As Byte)

With this Code I send the Stream:
Sub test(msg As String)
Dim mm As MyMessage
mm.Initialize
mm.Kennung="#"
mm.MSG="#"
mm.Text1="#"
mm.Text2="#"
'convert the Image To bytes
Dim out As OutputStream
Dim image1 As Bitmap
image1.Initialize(File.DirAssets,"kwp.jpg")
out.InitializeToBytesArray(0)
image1.WriteToStream(out, 100, "JPEG")
out.Close
mm.FileToSend=out.ToBytesArray
CallSub2(Starter, "SendData", ser.ConvertObjectToBytes(mm))
End Sub

The same declaration in B4J:
Type MyMessage (Kennung As String, Text1 As String,Text2 As String,MSG As String, FileTosend() As Byte)

Receive the Stream in B4J with this code:
Sub AStream_NewData (Buffer() As Byte)
Dim mm As MyMessage
Dim MyBuffer() As Byte

mm=ser.ConvertBytesToObject(Buffer)

Dim in As InputStream
If mm.FileToSend.Length>0 Then
in.InitializeFromBytesArray(mm.FileToSend, 0, mm.FileToSend.Length)

Dim bmp As Image
bmp.Initialize2(in)

Dim Out As OutputStream = File.OpenOutput(File.DirApp, "kwp1.jpg",False)
bmp.WriteToStream(Out)
Out.Close
End If

End Sub

The problem is, that the image is not received at the B4J Application. The FileToSend() is null:
upload_2017-8-22_23-13-52.png
upload_2017-8-22_23-13-52.png


The strange thing is, if I use the Network example with the same code, that the Image is received:
upload_2017-8-22_23-15-26.png
upload_2017-8-22_23-15-26.png


Can someone help me, please?
I'm stocking right now. No idea.

Thank you very much and
Best Regards
Manfred
 

millstone

Member
Licensed User
Longtime User
1. Please use [code]code here...[/code] tags when posting code.

2. It is difficult to read your post with all these screenshots.

Hello,
thank you for the answer. Sorry for the confusing. It is my first tread.

I have declared this:
B4X:
    Type MyMessage (Kennung As String, Text1 As String,Text2 As String,MSG As String, FileTosend() As Byte)

I use in my app this code in a own Modul and whant to send Strings and an Image for Test:
B4X:
Sub test(msg As String)
    Dim mm As MyMessage
    mm.Initialize
    mm.Kennung="#"
    mm.MSG="#"
    mm.Text1="#"
    mm.Text2="#"
    'convert the Image To bytes
    Dim out As OutputStream
    Dim image1 As Bitmap
    image1.Initialize(File.DirAssets,"kwp.jpg")
    out.InitializeToBytesArray(0)
    image1.WriteToStream(out, 100, "JPEG")
    out.Close
    mm.FileToSend=out.ToBytesArray
    CallSub2(Starter, "SendData", ser.ConvertObjectToBytes(mm))
End Sub

If I send the stream to the B4J Application, the Image is not received on PC site.
I debug the B4J Application:
upload_2017-8-23_14-53-7.png


If I use your Network example with exact same code from above, the Image is received.
I debug the B4J Application:
upload_2017-8-23_14-55-30.png


I have no Idea what happen.
Thank you and best Regards.
Manfred
 
Upvote 0

millstone

Member
Licensed User
Longtime User
The B4A code looks correct. Are you sure that the type is declared correctly in the B4J program?
Dear Erel,

This is the declaration in my B4A App in the Main Activity:
B4X:
    Type MyMessage (Kennung As String, Text1 As String,Text2 As String,MSG As String, FileTosend() As Byte)

This is the declaration in B4J Application:
B4X:
    Type MyMessage (Kennung As String, Text1 As String,Text2 As String,MSG As String, FileToSend() As Byte)

This is the code in the B4J Application:
B4X:
Sub AStream_NewData (Buffer() As Byte)

    Dim mm As MyMessage
   
    mm=ser.ConvertBytesToObject(Buffer)


    Dim in As InputStream
    If mm.FileToSend.Length>0 Then
        in.InitializeFromBytesArray(mm.FileToSend, 0, mm.FileToSend.Length)
   
        Dim bmp As Image
        bmp.Initialize2(in)
   
        Dim Out As OutputStream = File.OpenOutput(File.DirApp, "kwp1.jpg",False)
        bmp.WriteToStream(Out)
        Out.Close
    End If
    'Dim MyDate As String
    'Dim MyTime As String

    'MyDate=DateTime.Date(DateTime.Now)
    'MyTime=DateTime.Time(DateTime.Now)
   
End Sub

It only works with your Network example with my original code and also with the same type
declaration.
In my App the only difference is, that the code is running not in the Main Activity, but in a own Modul.
Strings are passed without any problems, in both Applications.

Thanks for help.
Manfred
 
Upvote 0

millstone

Member
Licensed User
Longtime User
Hello,

the types are declared in the main module.
See my last post.

I wrote:
This is the declaration in my B4A App in the Main Activity:
B4X:
Type MyMessage (Kennung As String, Text1 As String,Text2 As String,MSG As String, FileTosend() As Byte)

Regards
Manfred
 
Upvote 0

millstone

Member
Licensed User
Longtime User
Hello,

thank you for the replay.

I send you now:
1. KWP-Project.zip -- it is the B4A Projekt. Image will not received.
2. MServer-BJ4-Project

Thanks for support.

regards
Manfred
 

Attachments

  • MServer-B4J-Project.zip
    5.8 KB · Views: 228
  • KWP-Project.zip
    110.7 KB · Views: 287
Upvote 0

millstone

Member
Licensed User
Longtime User
Hello all,

thank's so far, Erel and fixit30, for the suggestion.
The strange thing is, if I use Erels Network example, the serialized image is sent. In my project, it is null received.
Maybe it works just in the main activity. Right now, i use a separate activity. I will do some further investigation, and
post my results later.

Best Regards
Manfred
 
Upvote 0

millstone

Member
Licensed User
Longtime User
Hello all,

i found now a solution for my problem.
The renaming of the type, which include the image, have solved my problem.

Declaration in my B4A project:
B4X:
    Type MyMessage (Kennung As String, Text1 As String,Text2 As String,MSG As String, Image() As Byte)

Declaration in my B4J project:
B4X:
    Type MyMessage (Kennung As String, Text1 As String,Text2 As String,MSG As String, Image() As Byte)

Now, the image Byte Array is OK:
upload_2017-8-27_22-45-44.png


If I use the Type Name FileTosend() As Byte, see my posts before, it was not working. It was always null.

Strange....

But anyway... Thanks to all for the great B4X community.

Best Regards
Manfred
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
This is the declaration in my B4A App in the Main Activity:
B4X:
Type MyMessage (Kennung As String, Text1 As String,Text2 As String,MSG As String, FileTosend() As Byte)
This is the declaration in B4J Application:
B4X:
Type MyMessage (Kennung As String, Text1 As String,Text2 As String,MSG As String, FileToSend() As Byte)
Please note that "Type" fields are case sensitive. In your B4A app, you have FileTosend, in your B4J app you have FileToSend. I've checked the B4A User's Guide (1.7) and B4A Beginner's Guide (3.3) and see no mention of that. I've just happened to run into an answer by @Erel here that mentions that "type field names are case sensitive".
 
Upvote 0

millstone

Member
Licensed User
Longtime User
Hello OliverA,

thank you very much for this advise :)
It works now. A classic "human error"

Thank' s to all.

Manfred
 
Upvote 0
Top