Android Question Release of buffer Astreams_Newdata


Licensed User
Longtime User
After 2 days of fiddling, I finally gave up....:(

Building a kind of challenge response system with Asyncstreams.

The Server/Host part is a simple Python script on my Linux PC. The connection is OK.

The android asks the server for a 'challenge'. I do see that the server sends one.
that part is working...DUHH

I can not though, use the newdata buffer data in my response..because the buffer is empty. The host did send a challenge...but the buffer is empty.
The second time I ask for a challenge, the newdata buffer gives me the data from the previous challenge o_O
The third time...the buffer gives me the data from the second challenge...and so on.:eek:

It looks like the buffer is only filled (or usable) after the whole sub has finished.

I tried to split the challenge and response in two service modules hoping that the newdata would be filled, with the current challenge, but no.
I build in a timer to wait, and than read the buffer...but still only the data from the previous challenge.

What should i do to, kind of, release the buffer and use the newdata of the current challenge?



Licensed User
Longtime User
I think this is the relevant code.....

Like I said. I can transmit and do receive...but I can cannot 'process' the relevant Rx_challenge because it's not the present Rx_challenge but a (prior) buffered one...


Sub send2
If AStreams.IsInitialized = False Then Return
     ' both rx_challenge and tx_challenge are declared in Globals
   Log("challenge in buffer BEFORE 'asking for CHALLENGE' is send"&rx_challenge)
   tx_challenge="<c>ask for challenge</c>"
    Dim buffer1() As Byte
     Log("challenge send: "&tx_challenge)   
     ' this is the main code. I Did try
     ' to split this in 2 service modules
     ' and with a timer between "challenge send"
     ' and "received challenge"
   Log("received challenge in buffer "&rx_challenge)
   ' here I just echo the received rx_challenge
   ' In the productionversion rx_challenge is recalculated
   ' based on the original rx_challenge
   msg="<c>response: "&rx_challenge&"</c>"
     buffer1 =msg.GetBytes("UTF8")
     Log("response send by B4A: "&msg)
   Log ("nothing received")   
End Sub

Sub AStreams_NewData (buffer() As Byte)
  rx_challenge = BytesToString(buffer, 0, buffer.Length, "UTF8")
  Log(" received challenge in Newdata: "&rx_challenge)
End Sub
Upvote 0