-1
OutputStream的收盘前收到的消息我在服务器的InputStream为什么不能在TCP
DataInputStream in=new DataInputStream(c1.getInputStream()) ; System.out.println(in.readUTF());
它的工作原理使用这样的代码在我的客户
DataOutputStream out = new DataOutputStream(client.getOutputStream());
out.writeUTF(mssage);
out.flush();
while(true){
}
与此代码。 但是,如果我用这个下面的代码在我的客户
OutputStream out=client.getOutputStream();
out.write(mssage.getBytes());
out.flush();
while(true){
}
这个代码在我的服务器
InputStream in= c1.getInputStream();
byte [] b=new byte [32];
while((in.read(b))!=-1){
toprint+=new String (b);
}
System.out.print(toprint);
,直到我关闭客户端或关闭的OutputStream,服务器无法接收按摩会出现连接重置错误。 是什么原因?
但它为什么不关闭套接字或DataOuputStream,当我使用DataOuputStream在我的客户端发送和使用DataInputStream类在我的服务器来读取。 –
我无法制作头部或尾部,但它与'DataInput/OutputStream'无关。这是所有套接字流的行为方式。您正在读取数据流结束,数据流结束意味着对等方已断开连接。尝试在收到字符时打印这些字符。 – EJP