How to control the Channel out of Handler object
Thomas Bocek
bocek at ifi.uzh.ch
Tue Sep 15 14:13:57 EDT 2009
Hi Olek,
olekg wrote:
> Hello,
>
> As I written in another thread I try to build Comet/Streaming solution with
> Netty. I have partialy chieved me goal for one-client connection.
>
> The idea for my application is to run timer in singleton object which
> updates all registered Event objects, registered in HttpRequestHandler. In
> other words when obtain messageReceived event I do not build the response.
> Instead I pass the Event object to be many times used to fill client with
> data.
>
> Unofortuanately I have lost the control over transmission erreors. I have
> the code :
>
> DefaultHttpChunk chunk = new DefaultHttpChunk( buf);
> ChannelFuture chf = e.getChannel().write(chunk);
> if ( chf.isSuccess() ) {
> System.out.println("Wyprowadzono porcję skryptu przez kanał.");
> } else {
> System.out.println("Error");
> Throwable thr = chf.getCause();
> if( thr != null ) {
> System.out.println( thr.getMessage());
> } else {
> System.out.println("Null error object.");
>
> }
>
> }
>
> Regardless of the data is sent correctly or not I malway obtain "Error"
> message and "Null error object". I want to know when client discnnects.
>
> When I am inside HttpRequestHandler the exceptionCaught event is fired
> correctly. What if I am outside ?
Before using the channel future, make sure the future finished by
calling chf.awaitUninterruptibly(); Otherwise you often see the default
value of ChannelFuture, which is false.
Thomas
More information about the netty-users
mailing list