users@grizzly.java.net

Re: how to detect a client that close his connection to the server ?

From: Jeanfrancois Arcand <Jeanfrancois.Arcand_at_Sun.COM>
Date: Wed, 12 Nov 2008 21:54:38 -0500

Salut,

Survivant 00 wrote:
> I just find a bug in my application. I don't know how to get notify
> when I client close the connection with the server. (TCP)

I can't remember when we talked about that, but I was under the
impression the ReadFilter has an API to register listener when the
connection get closed. But looking at the code, I guess I've dreamed....

The solution is to write your own SelectionKeyHandler and monitor the
SelectionKey that are closed. But I don't really like the solution.

The logic should really be in ReadFilter, but I suspect you are using
ProtocolParser and let me investigate more...Alexey and John might wakes
faster than me on that :-)

A+

-Jeanfrancois


>
> here the init of the server
>
> public void init(){
>
> System.out.println("listening for incoming TCP Connections on
> port : " + f_port);
> try {
>
> f_controller = new Controller();
> TCPSelectorHandler tcpSelectorHandler = new
> TCPSelectorHandler();
> tcpSelectorHandler.setPort(f_port);
>
> Pipeline pipeline = new DefaultPipeline();
> pipeline.setMaxThreads(5);
>
> f_controller.setPipeline(pipeline);
>
> tcpSelectorHandler.setSelectionKeyHandler(new
> BaseSelectionKeyHandler());
>
> f_controller.addSelectorHandler(tcpSelectorHandler);
>
> QuoteQueryProtocolFilter protocolParser = new
> QuoteQueryProtocolFilter();
> QuoteQueryManagerFilter quoteManagerFilter = new
> QuoteQueryManagerFilter(f_quoteManager);
>
> final ProtocolChain protocolChain = new DefaultProtocolChain();
> protocolChain.addFilter(protocolParser);
> protocolChain.addFilter(quoteManagerFilter);
> ((DefaultProtocolChain)
> protocolChain).setContinuousExecution(true);
>
>
> ProtocolChainInstanceHandler pciHandler = new
> DefaultProtocolChainInstanceHandler() {
>
> public ProtocolChain poll() {
>
> return protocolChain;
> }
>
> public boolean offer(ProtocolChain protocolChain) {
> return false;
>
> }
> };
>
> f_controller.setProtocolChainInstanceHandler(pciHandler);
> try {
> f_controller.start();
> } catch (IOException e) {
> e.printStackTrace();
> }
>
>
> } catch (Exception e) {
> System.exit(-10);
> }
> }