Non-Netty client - Any help please, nearly there!
Frederic Bregier
fredbregier at free.fr
Sun Dec 28 04:12:04 EST 2008
Hi,
I didn't try to run the test, but I've got two directions for you...
Perhaps I'm completely wrong, but could it be possible that your
client has something wrong with the reading from the server?
while (totalBytesRcvd < 300) {
if ((bytesRcvd = clntChan.read(readBuf)) == -1) {
//throw new SocketException("Connection closed prematurely");
break;
}
totalBytesRcvd += bytesRcvd;
Thread.currentThread().sleep(500);
}
System.out.println("Total Bytes Received are: " + totalBytesRcvd);
byte [] ary = readBuf.array();
It seems you force the client to receive 300 bytes whatever the real size
of the Message object... What if the message is smaller or bigger ?
If the message is smaller, then the client will block for ever since
the server will wait for the client to send a new message before to
continue,
so a deadlock.
If the message is bigger, bigger than 1000 in fact since it is the size of
the buffer, then the client will not wait for the end of the message
and just sends a new message then will read for the next message,
probably having some bytes from the first message in the beggining of
the other byte array. Here could be a possible source of error.
However, I think it should be OK since the first message seems to be
less than 1000 bytes but more than 300 bytes.
And the second message should be ok too as the first bigger than 100 bytes
and
less than 1000b.
The second possibility is about the ByteBuffer itself you use.
After each "while" loop, you probably should call readBuf.clear()
since readBuf.array() does nothing on the buffer itself.
Perhaps your buffer starts at the previous position in the readBuf
object so that you readObject() call is wrongly placed ?
Also don't forget to close/flush you ObjectInput/OutputStream.
I'm not sure it will help you, but it is my two cents... ;-)
Frederic
-----
Hardware/Software Architect
--
View this message in context: http://n2.nabble.com/Non-Netty-client-tp1771503p2017883.html
Sent from the Netty User Group mailing list archive at Nabble.com.
More information about the netty-users
mailing list