users@grizzly.java.net

Newbie question: Understanding CallbackHandler

From: CigarMan <strudeau_at_bluetreewireless.com>
Date: Thu, 20 Dec 2007 07:21:30 -0800 (PST)

I have been trying to use Grizzly for the past couple of days to write an
asynchronous TCP/UDP client. Basically, I want my client to write a bunch of
bytes (request) to a remote server and eventually receive a response as a
bunch of bytes.

Looking at the unit tests available with Grizzly framework module, it looks
like I have to write a callbackhandler to handle the asynchronous response.
Unfortunately I don't understand the callbackHandler interface.

In TCPAsynchQueueReaderTest.java, the method public void
onConnect(IOEvent<Context> ioEvent) seems to register a key with the OP_READ
event.

 ioEvent.attachment().getSelectorHandler().register(key,
SelectionKey.OP_READ);

First of all, I'm kind of lost to what that whole registration means, I have
very little cue as to what this onConnect method is trying to achieve (I
would really appreciate if you could post references on your websites so
that new developpers can get the appropriate background knowledge before
digging into your framework). I assume this has to do with having the
selectionKey try to perform a read operation once a connection is
established with the client.

But yet in the same example, the onRead and onWrite method do nothing!

Basically, as a user, I need to know where can I put my application code
that will get the bytes received and perform my business logic (I would
really like to understand how to write a callbackhandler! :.).

Is there a higher level API provided with the Grizzly framework for writing
basic clients and servers that send bytes over TCP/UDP (not HTTP)?

Also, one last question (for now :.), do I need a protocol filter on the
server side if every write operation write operation from the client writes
a full request to the channel? (Sorry, I don't really understand behind the
rationale of the protocolfilter, I don't really understand what kind of
issue it addresses.


Thanks for your help,


Simon


P.S.: Don't hesitate to write back in french if you feel like it, I'm from
Montreal.

Once I get a better understanding of how to write a basic Grizzly asynch
client and server, I will try to write a tutorial for newbies (like myself)
about it. I'll let you know.
-- 
View this message in context: http://www.nabble.com/Newbie-question%3A-Understanding-CallbackHandler-tp14438446p14438446.html
Sent from the Grizzly - Users mailing list archive at Nabble.com.