Non-Netty client - Any help please, nearly there!
Trustin Lee
trustin at gleamynode.net
Mon Dec 29 19:20:07 EST 2008
On Tue, Dec 30, 2008 at 6:13 AM, skhalid <shahbaz.khalid at gmail.com> wrote:
> Sorry Trustin - there was a mistake in the code - it should have been the
> Message object being sent back, but I was experimenting to see if I could
> serialise the object on my own and send it back as an array back to the
> client (strangely enough this works, and after stripping the first 23 bytes
> in the array I get on the client side, I can convert/cast the rest of the
> bytes into my own object).
>
> For the code that I am submitting, there is only one change - the Message
> class is actually the Customer class (I only renamed the class in the
> original thread post to , uh, look respectable - why would a telnet server
> return customer objects?).
>
> But please find the code attached - ignore the other methods for the time
> being and only focus on what's going on in the main method of
> TCPEchoClientNonblocking class.
>
> I would really appreciate your help.
I looked into your code and there's one problem in
TCPEchoClientNonBlocking.java. You should not create a new
ObjectInputStream for each read object but keep using the same
ObjectInputStream instance. Otherwise, the client will expect the
Object stream header (i.e. magic value), while CompatibleObjectEncoder
writes the header only once because CompatibleObjectEncoder keeps
using the same ObjectOutputStream instance.
To fix this issue, I'd recommend you to use ObjectEncoder,
ObjectDecoder, ObjectDecoderInputStream, and ObjectEncoderOutputStream
instead of CompatibleObjectEncoder, CompatibleObjectDecoder,
ObjectInputStream, and ObjectOutputStream. Just replacing the four
classes should fix it.
> P.S. The only reason why I am having to revert to a custom NIO client is
> that the Android does not like the TimeBasedUuidGenerator class (because
> android JVM does not have the java.lang.management.* package). Otherwise I
> would have used the netty client.
That's interesting. I have never thought about Android platform so
far, and now I'd like to make Netty run there without a modification.
Could you let me know what classes are unsupported besides
java.lang.management.*?
HTH and thanks in advance,
--
Trustin Lee, Principal Software Engineer, JBoss, a division of Red Hat
--
what we call human nature in actuality is human habit
--
http://gleamynode.net/
More information about the netty-users
mailing list