Salut,
Survivant 00 wrote:
> I been able to parse the data and get a valid message using XXX
>
> not I want to send back data to the client.
>
> I found differents ways to send to the client, but don't know which one
> I should use.
>
> ctx.getAsyncQueueWritable().writeToAsyncQueue(buffer, null, null, true);
>
> or
>
> SelectableChannel channel = context.getSelectionKey().channel();
> try {
> //DEBUG HERE.. just to see how that work.
> ByteBuffer writeBuffer =
> ByteBuffer.allocateDirect(query.length());
>
> writeBuffer.put(query.getBytes());
>
> writeBuffer.flip();
>
> if (context.getProtocol() == Controller.Protocol.TCP) { //
> TCP case
> OutputWriter.flushChannel(channel, writeBuffer);
> }
> } catch (IOException ex) {
> throw ex;
> }
>
The former will block until all the bytes are written. When I say block,
I mean the calling Thread will block. The OutputWriter internally use a
pool of temporary Selector to make sure writes are always executed entirely.
With async queue write (the later), the calling thread will not block.
instead, the async queue mechanism will make sure your write operation
is successful. Depending on the protocol, picking one or the other make
a big difference. HTTP use OutputWriter, SIP use async queue.
A+
-- Jeanfrancois
>
>