c******n 发帖数: 4965 | 1 after connection,
the server side just spits out a short string , which I know is less than
100 chars long.
so supposedly I could just wait 1 second, and read from the stream
whatever is available.
but the problem is that the stream does not terminate by a "\n", so I
can't do
readline
read(byte[] , int, int) doesn't work either, since I don't know the actual
length of the string.
apparently I can use NIO for this, but is there a simpler method?
Thanks | m****r 发帖数: 6639 | 2 can yuou read one byte at a time until there is no more to be read?
【在 c******n 的大作中提到】 : after connection, : the server side just spits out a short string , which I know is less than : 100 chars long. : so supposedly I could just wait 1 second, and read from the stream : whatever is available. : but the problem is that the stream does not terminate by a "\n", so I : can't do : readline : read(byte[] , int, int) doesn't work either, since I don't know the actual : length of the string.
| c******n 发帖数: 4965 | 3 define "no more to be read" ? :)
InputStream.isready() ??
looks a bit clumsy....
【在 m****r 的大作中提到】 : can yuou read one byte at a time until there is no more to be read?
| c******n 发帖数: 4965 | 4 define "no more to be read" ? :)
InputStream.isready() ??
looks a bit clumsy....
【在 m****r 的大作中提到】 : can yuou read one byte at a time until there is no more to be read?
| h*****0 发帖数: 4889 | 5 服务器端发送完后会close吧?如果服务器竟然不close,把socket吊在那里,那神仙也
没办法啊……
如果会关,那简单,read(byte[])就成,用循环,看返回值是否为-1,为-1时表明已经
读完了。具体请参考j2se doc
【在 c******n 的大作中提到】 : after connection, : the server side just spits out a short string , which I know is less than : 100 chars long. : so supposedly I could just wait 1 second, and read from the stream : whatever is available. : but the problem is that the stream does not terminate by a "\n", so I : can't do : readline : read(byte[] , int, int) doesn't work either, since I don't know the actual : length of the string.
|
|