2
我有一个程序连接到服务器,并通过输入和输出数据流发送/接收数据。 我想调试它,看看是否正在传递的消息是正确的,所以我必须读取通过流发送什么,但连接有1秒超时。 (在服务器端,我不能控制) 有没有办法听流,所以我可以从它的数据到控制台,并有数据仍然被发送?Java:“聆听”DataStream
public void foo(DataInputStream in, DataOutputStream out){
//Some code to make the console write whatever is sent in the out stream
//And received in the in stream.
out.writeUTF("SOME TEXT");
String s = in.readUTF();
}
Drats!打我吧:)。得到第二个:TeeInputStream是这样的任务的道路,真相和光芒。 – Femi 2011-05-07 15:20:36
不幸的是我不得不使用DataInputStream(和output)类,所以我不能使用任何不能扩展它的东西。 – Benny 2011-05-07 15:50:03
@Benny - 'TeeInputStream'是一个装饰器:无论你创建DataInputStream,你都会这样做。但是,作为构建链的一部分,您可以插入'TeeInputStream'。 – Anon 2011-05-07 15:55:55