Thales' cellular IoT products business is now part of Telit Cinterion, find out more.

You are here

Reading from a Socket InputStream | Telit Cinterion IoT Developer Community

March 6, 2017 - 2:57pm, 3473 views

Hello,

I have a question about data reading with InputStream when using SocketConnection.

Now, in my project, I'm reading 1 byte data at each cycle using InputStream.read() method after checking data availablity with available() method. If stream started and data not available for some time, say 100 ms, I suppose data end is reached and decide it to be a complete packet. But I this method does not seem proper and I don't want to read 1 byte at each cycle.

How can it be done more properly?

Are TCP/UDP packets written to buffer as a whole or partially at low level? When I checked the data in buffer with available() method, if there is data , can I assume it is a complete, whole TCP/UDP data packet? If it is a whole packet, I can read it to a byte array completely at one cycle.

Best Regards,

Ergün.