Client disconnect

matthias.s. matthias.scudlik at pangora.com
Tue May 5 11:41:08 EDT 2009


Im still testing if netty can handle my requirements.
One thing i can not get work properly is disconnecting the client from the
server (both netty)

The problem is that messages that are not sent yet won't be sent and the
connection is closed.

But i want that all messages are sent before i get disconnected.

I tried ChannelFuture.close and Channels.disconnect() Channels.unbind() and
so on.
I used channelFuture.awaitUninterruptibly() which didn't help as well.

In my Case i created a Client like this:

      NettyClient client = new NettyClient();
      client.setClientConfig(config);
      ExecutorService clientThreadPool = Executors.newCachedThreadPool();
      ExecutorService workerThreadPool = Executors.newCachedThreadPool();
      client.setChannelFactory(new
NioClientSocketChannelFactory(clientThreadPool, workerThreadPool));
      client.setBootstrap(new ClientBootstrap(client.getFactory()));
      client.getBootstrap().setPipelineFactory(new MyChannelPipeline());
      client.getBootstrap().setOption("reuseAddress", true);
      client.getBootstrap().setOption("connectTimeoutMillis",
client._timeout);


NettyClient is a simple "wrapper" class implementing a simple interface.

on my connect method i set the channelfuture and in my send() methods i use
this channelfuture object.


   public void connect( SocketAddress address ) {
      setChannelFuture(getBootstrap().connect(address));
      ChannelFuture future = getChannelFuture().awaitUninterruptibly();
      if ( future.isSuccess() ) {
         setStartTime(System.currentTimeMillis());
      }
   }


The testcase was something like this:

client.connect();

// 100 000 times
for( int i = 0; i < 100000; i++) {
client.send(foo);
}

client.send("done");

client.disconnect();

With client.disconnect() the previous "done" is never sent.

my send() method that i use is:

   public <T> void send( T object ) {
      ChannelFuture future = getChannelFuture();
      Channel channel = future.getChannel();
      if ( future.isSuccess() ) {
         channel.write(object);
      }
   }

The Pipeline consists of ObjectEncoder, ObjectDecoder on both client and
server side, and the server has another handler which will dispatch my
different objects.
I have to be sure that each object is beeing sent, unless an ioexception or
something like that occurs. But as soon as disconnect() is called (i tried
each kind of way iexplained before to disconnect) the client disconnects
immediately. Is there a way of asking weather the sendQueue is empty?

Either i did something wrong or i think this is a serious bug. Each of my
about 10 clients will have to send millions of object in my project to the
same server.

I used netty 3.0.2GA and 3.1.0BETA2

thanks 
-- 
View this message in context: http://n2.nabble.com/Client-disconnect-tp2798147p2798147.html
Sent from the Netty User Group mailing list archive at Nabble.com.




More information about the netty-users mailing list