static final private Logger LOG = LoggerFactory.getLogger(NioEchoServer.class);
public static void main(String[] args) {
LOG.info("starting echo client");
final NioTcpClient client = new NioTcpClient();
client.setFilters();
client.setIoHandler(new AbstractIoHandler() {
@Override
public void sessionOpened(final IoSession session) {
LOG.info("session opened {}", session);
}
@Override
public void messageReceived(IoSession session, Object message) {
LOG.info("message received {}", message);
if (message instanceof ByteBuffer) {
LOG.info("echoing");
session.write(message);
}
}
@Override
public void messageSent(IoSession session, Object message) {
LOG.info("message sent {}", message);
}
@Override
public void sessionClosed(IoSession session) {
LOG.info("session closed {}", session);
}
});
try {
IoFuture<IoSession> future = client.connect(new InetSocketAddress("localhost", 9999));
try {
IoSession session = future.get();
LOG.info("session connected : {}", session);
} catch (ExecutionException e) {