throws IOException {
final IoAcceptor acceptor = new SocketAcceptor();
IoAcceptorConfig config = new SocketAcceptorConfig();
config.setDisconnectOnUnbind(true);
((SocketSessionConfig) config.getSessionConfig()).setReuseAddress(true);
acceptor.bind(new InetSocketAddress(ip, port), handler, config);
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
acceptor.unbindAll();
}