You don't need a loop that goes "if available() .... Thread.sleep".
Just calling read() will block until there is data available, and do so more efficiently than Thread.sleep (for a blocking socket, that is).
Also, your loop always tries to read 1024 bytes. If the other side writes some number of bytes that's less than that, and gracefully closes the connection, the loop will never complete.
Should be easy to find out where things go wrong by using the debugger, you can select the thread running this code in the Debug perspective and click "pause". After that, look at the call stack.
-- Kostya 03.05.2011 8:41, Anila Khwaja пишет:
I've written a piece of code which connects through socket and receive data to load bitmap image on phone ... it works perfectly in android 2.3.X but blocks the data on android 2.2 when bytes read reached 2048.. it doesn't read anything more than that and get stucked over there I read on multiple forums that android 2.2 block large files but if the data on stream can split into chunks then it can be read. here is the piece of code i've written for it isRvcdData = socket.getInputStream(); byte[] chunk = new byte[1024]; if (socket.isConnected()&& !socket.isClosed()) { while (isRvcdData.available()< chunkLength) { Thread.sleep(10); } iByteLengthRead = isRvcdData.read(chunk, 0, 1024); } please help me out as how to read the whole data from stream on android 2.2
-- Kostya Vasilyev -- http://kmansoft.wordpress.com -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en