Android Question is asyncstream need to be queued ?

Addo

Well-Known Member
Licensed User
Longtime User
i a using asyncstream as a tcp client to receive text and split them each 10 milliseconds

this is the text that i am receiving from the server

B4X:
1GETNAMES&Mark~active~~105~
1GETNAMES&TOM~active~~101~

this records could increased based on database

my newdata to recive those records inside service looks like this

B4X:
Public Sub NEWCHATDATA(data() As Byte)
    
Dim arrvmsg As String



arrvmsg = BytesToString(data, 0, data.Length, "UTF-8")
arrvmsg = arrvmsg.Trim
arrvmsg = arrvmsg.Replace(CRLF, "")

If arrvmsg.Length = 0 Then
Log("Error")
Return
End If


Handlcmdstrings(arrvmsg)

End Sub



Public Sub Handlcmdstrings(CMDS As String)
Dim userlinadd As String

Try


If CMDS.Length = 0 Then
Log("Error")
Return
End If

Log(CMDS)





paramnum = Regex.Split("\&", CMDS)

If paramnum(0) = "1GETNAMES" Then
userlinadd = paramnum(1)
Log(paramnum.Length)

CallSub2(Main, "DISPLAYUSER", userlinadd)

End If

Catch
Log("Error")
End Try


   
End Sub

i got a problem to split the received records using regex.split the length should always count 2 based on those 2 records

but some times it gets conflicted of the messages received too fast so the length becomes 3 and the split faild

the split should do the records like following
B4X:
paramnum(0) will be equal to 1GETNAMES' and paramnum(1) should always get the rest of result for each sending line

but some times records got conflicted together is what i am doing is right to handle data with asyncstream ?
 

OliverA

Expert
Licensed User
Longtime User
Use AsyncStreamsText (https://www.b4x.com/android/forum/t...rking-with-streams-of-text.27002/#post-156325) if you are dealing with text communication that uses line-feeds as a text line ending. AsyncStreams does not really know what you consider to be a complete message and each message may raise one or more New_Data events and you have to figure out when New_Data has received a complete message. AsyncStreams does have a prefix mode (https://www.b4x.com/android/forum/threads/b4x-asyncstreams-tutorial.7669/) that will manage this for you, but then sending and receiving applications must use prefix mode (which may not be available for/understood by non B4X/.Net applications).
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
which may not be available for/understood by non B4X/.Net applications
The Sender-Part is a Delphi-application if i read it right in the past.

@PassionDEV :
The Queueing you need to do by yourself in the receiving B4A Application if there is no such thing as AsyncStreamText in Delphi.
 
Last edited:
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Upvote 0

Addo

Well-Known Member
Licensed User
Longtime User
@OliverA Asyncstreamtext works fine and those conflicts are now solved again you saved me for bazillion times

In the future I will implemented a server side using b4j and get ride of all delphi hell altogether

I am just prepare to full migration
 
Upvote 0
Top