Private Sub AStream_NewData(Data() As Byte)
Buffer.Append(Data) 'Buffer is a class global B4XBytesBuilder
End Sub
'send message
Dim timeout As Long = DateTime.Now + 1000 'one second
Dim result() As Byte
Do While DateTime.Now < timeout
Sleep(50)
If Buffer.Length > ... Then
result = Buffer.SubArray2(...)
Buffer.Remove(...)
Exit '<---------------
End If
If result.Length = 0 Then
Log("timeout")
Else
Log("work with response")
End Sub