I created a ServerSocket and read messages from different clients. One of the clients insisted that my application does not behave correctly after they sent their messages. I managed to get a TCP trace and saw that they really sent their messages, but my server application did not read any data from the socket. I get a thread dump and everything seems to be ok there:
"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)
What may be the reason that I could not read messages from the stream? Other clients do not suffer this kind of problem by the way.
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;
}
}
}