java socket read 阻塞_java Socket编程中read方法的阻塞问题,求高手解答 代码如下

看源码啊DataInputStream的read方法。

/**

* Reads some number of bytes from the contained input stream and

* stores them into the buffer array b. The number of

* bytes actually read is returned as an integer. This method blocks

* until input data is available, end of file is detected, or an

* exception is thrown.

public final int read(byte b[]) throws IOException {

return in.read(b, 0, b.length);

}

This method blocks

* until input data is available, end of file is detected, or an

* exception is thrown.

你第一次读,就把数据读完了,接下来没有可读的了。

/**

* Returns an estimate of the number of bytes that can be read (or

* skipped over) from this input stream without blocking by the next

* caller of a method for this input stream. The next caller might be

* the same thread or another thread. A single read or skip of this

* many bytes will not block, but may read or skip fewer bytes.

*

* This method returns the result of {@link #in in}.available().

*

* @return an estimate of the number of bytes that can be read (or skipped

* over) from this input stream without blocking.

* @exception IOException if an I/O error occurs.

*/

public int available() throws IOException {

return in.available();

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值