无法弄清楚何时打破循环 [英] Can't figure out when break the loop

查看:97
本文介绍了无法弄清楚何时打破循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有链接都指向此:

all links point on this:

while((c = is.read()) != -1) {
   // do something with the response
}


但是这种想法似乎是错误的,因为此循环是ENDLESS,我也尝试在响应后通过服务器"-1"发送-无济于事.我很困惑.
[只是试图从服务器接收响应]


but this conception seems like wrong, because this loop is ENDLESS, I also tried to send by server "-1" after response - not helped. I confused.
[Just trying to receive a response from the server]

推荐答案

-1"-1"不同.你在读什么? is.read()到达EOF时返回什么?
well -1 is not that same as "-1". What are you reading? What does is.read() return when it reaches EOF? that is what you want to look for.


是什么.当到达EOF时,read()返回?
字符串结束时is.read()返回255,但是:
What does is.read() return when it reaches EOF?
is.read() returns 255 when string was ended, but:
- 
while((c = is.read()) != 255) {
   // do something with the response
}


不是一个好的解决方案.
我认为唯一的方法是由服务器先传输字符串的LENGTH,然后再传输字符串.


is not a good solution.
I think the single way is to transfer by server LENGTH of string, and then, the string.


这篇关于无法弄清楚何时打破循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆