由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - how to read from a non-return socket stream?
相关主题
关于char和int的问题【跪求】java applet下怎么执行系统的一个程序?
help about bitstream writerconvert array to blob
怎样才能Firefox add-on和java程序之间传递数据Object stream & serilization有啥用处?
Java NIO 问题求教how to transfer data between two sockets
一个socket相关的问题问个很简单的问题?
socket and simple web browser怎样吧byte[]变成java.security.Key?
question on stream writeSocket Connection refused in high-loaded servers
有人用过异步Socket么?怎麼得到字符串中的raw bytes?
相关话题的讨论汇总
话题: read话题: stream话题: socket话题: byte话题: return
进入Java版参与讨论
1 (共1页)
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.

1 (共1页)
进入Java版参与讨论
相关主题
怎麼得到字符串中的raw bytes?一个socket相关的问题
How to parse the bytes[]socket and simple web browser
Re: How can I call another program from Java?question on stream write
JAVA中文TELNET MwTerm 1.000 Final有人用过异步Socket么?
关于char和int的问题【跪求】java applet下怎么执行系统的一个程序?
help about bitstream writerconvert array to blob
怎样才能Firefox add-on和java程序之间传递数据Object stream & serilization有啥用处?
Java NIO 问题求教how to transfer data between two sockets
相关话题的讨论汇总
话题: read话题: stream话题: socket话题: byte话题: return