Android Question InputStream.BytesAvailable "without blocking"

Erel

B4X founder
Staff member
Licensed User
Longtime User
If you call InputStream.ReadBytes on a network stream then the thread will wait for at least a single byte to be available. In most cases it will cause your app to crash. So you can check InputStream.BytesAvailable before calling ReadBytes to avoid blocking the main thread.

Before AsyncStreams object was available the proper way to read data from a network stream was by checking whether there are bytes available every x milliseconds (with a timer). However AsyncStreams is much better for such tasks and should be used instead.
 
Upvote 0
Top