Android Question How do I receive TCP client data Asynchronously

Levisvv

Member
Licensed User
Longtime User
I have an app that makes a socket connection to a server, and leave the connection open. This works and whenever a user presses a button I can receive it just fine on the server. The only sample code I coudl find for receiving data from the server seems to be blocking:

Dim tr As TextReader
tr.Initialize(Socket1.InputStream)
Dim sb As StringBuilder
sb.Initialize
sb.Append(tr.ReadLine) 'read at least one line
Do While tr.Ready
sb.Append(CRLF).Append(tr.ReadLine)
Loop

How can I Asynchronously receive the text messages from the server without need to stay in this loop?

Thanks in advance..
 

Levisvv

Member
Licensed User
Longtime User
Yes I found that and AsyncStreams works perfect thanks - I guess I just need to read a bit more next time...
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…