Crash with AStreams.InitializePrefix, success with AStreams.Initialize

jo1234

Active Member
Licensed User
Longtime User
Hi,

I have a problem to get my asynchstream initialized.

My app connects nicely to a windows server when I use:
B4X:
AStreams.[COLOR="Red"]Initialize[/COLOR](ClientSocket.InputStream, ClientSocket.OutputStream, "AStreamsIn")

However, I get a crash when I use:
B4X:
AStreams.[COLOR="Red"]InitializePrefix[/COLOR](ClientSocket.InputStream, False, ClientSocket.OutputStream, "AStreamsIn")
Error: java.lang.ArrayIndexOutOfBondsException: Offset out of bonds: -1


B4X:
Sub Process_Globals
    Dim ClientSocket As Socket      
    Dim AStreams As AsyncStreams
End Sub 

Sub cmdConnect_Click
    If Not(ClientSocket.IsInitialized) Then
       ClientSocket.Initialize("ClientSocket")
    End If
    ClientSocket.Connect(sIP, iPort, 2000)
End Sub

Sub ClientSocket_Connected (Successful As Boolean)
    If Successful Then
          AStreams.InitializePrefix(ClientSocket.InputStream, False, ClientSocket.OutputStream, "AStreamsIn")
    Else
        ClientSocket.Close 
    End If
End Sub

What am I doing wrong? :confused:

Thanks,
Johannes
 

jo1234

Active Member
Licensed User
Longtime User
No, the server is not the issue (the server is my VB6 program, which sends the prefix).

The problem is that the app crashes when it hits the line:
B4X:
AStreams.InitializePrefix(ClientSocket.InputStream, False, ClientSocket.OutputStream, "AStreamsIn")
Error: java.lang.ArrayIndexOutOfBondsException: Offset out of bonds: -1

Why?

thanks,
Johannes

PS: And yes, I did study the AsyncStreams tutorial ;)
 
Upvote 0

jo1234

Active Member
Licensed User
Longtime User
This code below is sufficient to reproduce the error. Of course, you would need the responding server, but as said, the server registers the connection request by the app. And there is no data exchange between the two, because the app crashes when initializing the stream.

Moreover: If I change AStreams.InitializePrefix to AStreams.Initialize everything runs smoothly.

Note that AStreamsIn_Error is NOT triggered.
The app crashes fatally when executing the line
B4X:
AStreams.InitializePrefix(ClientSocket.InputStream, False, ClientSocket.OutputStream, "AStreamsIn")

Complete code:
B4X:
Sub Process_Globals
    Dim ClientSocket As Socket      
    Dim AStreams As AsyncStreams
    Dim buffer() As Byte
End Sub 

Sub Globals
   Dim cmdConnect As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout ("main")
End Sub

Sub cmdConnect_Click
   If Not(ClientSocket.IsInitialized) Then
       ClientSocket.Initialize("ClientSocket")
    End If
    ClientSocket.Connect("192.168.1.3", 7610, 2000)
End Sub

Sub ClientSocket_Connected (Successful As Boolean)
    If Successful Then
          AStreams.InitializePrefix(ClientSocket.InputStream, False, ClientSocket.OutputStream, "AStreamsIn")
   Else
      ClientSocket.Close 
      End If
End Sub

Sub AStreamsIn_Error
   Msgbox (LastException.Message , "")
End Sub
 
Upvote 0

myriaddev

Active Member
Licensed User
Longtime User
idea

Note that when connected with your server using:
AStreams.Initialize, see if your server is sending/receiving
the correct byte order of size. Does your server
know when it is connected via AStreams.Initialize
or AStreams.InitializePrefix thus sends size or not ?
Hope this helps,
Jerry
 
Last edited:
Upvote 0

Michael eldred

Member
Licensed User
Longtime User
Program crashes in ASYNC prefix mode

I am having the exact same issue...

when initializing in normal mode I can communicate no problem,

when I switch to prefix mode the program crashes "An unexpected error has caused the forced closure of the program" type message..

I have programmed a microcontroller/bluetooth combo to send the required prefix.. I never recieve any data before it crashes
 
Upvote 0
Top