Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Moded out of code:java macro to code macro

...

You have to do it in two steps : first close your sessions, then dispose the connector. Of course, if you dispose your Connector first, then all the sessions will be closed. Here is the code :

Code Block
javajava
    ConnectFuture cf = connector.connect(new InetSocketAddress("localhost", 8080));

    // Get the close future for this session
    CloseFuture closeFuture = cf.getSession().getCloseFuture();

    // Adding a listener to this close event
    closeFuture.addListener((IoFutureListener<?>) new IoFutureListener<IoFuture>() {
            @Override
            public void operationComplete(IoFuture future) {
                System.out.println("The session is now closed");
            }
    });

    // Do the close requesting that the pending messages are sent before
    // the session is closed
    closeFuture.getSession().close(false);

    // Now wait for the close to be completed
    closeFuture.awaitUninterruptibly();

    // We can now dispose the connector
    connector.dispose();
{code:java}


h3. 

How

...

can

...

I

...

reconnect

...

to

...

server

...

after

...

my

...

client

...

session

...

is closed?

Here is an example code:

Code Block
 closed&#63;

Here is an example code:
{code:java}
public void sessionClosed( IoSession session ) throws Exception {
    // Wait for five seconds before reconnecting.
    Thread.sleep( 5000 );

    // Reconnect.
    connector.connect( session.getRemoteAddress(), this );
}

...

  1. Update the configuration value by running (30 seconds used in the example)
Code Block

   echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout
  1. Restart the networking component, for example by running
Code Block

  /etc/init.d/networking restart

or

Code Block

  service network restart