开发者

Android Socket Not Playing Nice

开发者 https://www.devze.com 2023-02-13 00:45 出处:网络
As Title. Here is code: InputStream is = tcp.getInputStream(); int bytesRead = 0; do{ byte[] byteIn = new byte[16* 1024];

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(b开发者_C百科yteIn, 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 :)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消