我创建了一个ServerSocket并读取来自不同客户端的消息。其中一位客户坚持认为,我的应用程序在发送消息后行为不正确。我设法得到一个TCP跟踪,并看到他们真的发送了他们的消息,但是我的服务器应用程序没有从套接字读取任何数据。我得到一个线程转储,并且在那里一切似乎都正常:java - 无法从套接字读取
"Reader Thread" daemon prio=3 tid=0x0ae8a000 nid=0x999 runnable [0x14525000]
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
什么原因导致无法从流中读取消息?其他客户不会遇到这种问题。
private byte[] readByte(int readCount) throws Exception {
int b;
int readedCount = readCount;
byte[] receiveBuffer = new byte[readCount];
while(true) {
if(readCount > 0) {
b = inputStream.read(receiveBuffer, readCount - readedCount, readedCount);
} else {
b = 0;
}
if(b < 0) {
throw new UnrecoverableSocketException("Connection is Broken");
} else {
readedCount = readedCount - b;
}
if(readedCount == 0) {
return receiveBuffer;
}
}
}
顺便说一句,我可以在TCP转储中看到TCP ACK消息 –