users@grizzly.java.net

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

From: Survivant 00 <survivant00_at_gmail.com>
Date: Wed, 12 Nov 2008 15:03:47 -0500

I could always check the SelectionKey isValid() when I want to send
something and if not unsubscribe the client, but is it the best way ?



2008/11/12 Survivant 00 <survivant00_at_gmail.com>

> 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)
>
> 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);
> }
> }
>