Taffy
Taffy

Reputation: 13

Android Socket Not Playing Nice

As Title.

Here is code:

InputStream is = tcp.getInputStream();
            int bytesRead = 0;
            do{
                byte[] byteIn = new byte[16* 1024];
                bytesRead = is.read(byteIn, 0, 16*1024);
                pStore.storeData(byteIn, 1024); 
                processMessage(pStore.readAll());
                pStore.clear();             
            }while(bytesRead>0);

Problem I have is that it never reaches the end of the while loop. Any suggestions would be muchly appreciated.

Thanks :)

Upvotes: 1

Views: 171

Answers (1)

Heiko Rupp
Heiko Rupp

Reputation: 30934

The Javadoc to InputStream.read() says:

This method blocks until input data is available

Which is what you may be seeing.

You may test with InputStream.available() if there is any data to be read first.

Upvotes: 3

Related Questions