int[] values = new int[args.length];
for (int i = 0; i < args.length; i++) {
values[i] = Integer.parseInt(args[i]);
}
SocketConnector connector = new SocketConnector();
// Change the worker timeout to 1 second to make the I/O thread quit soon
// when there's no connection to manage.
connector.setWorkerTimeout(1);
// Configure the service.
SocketConnectorConfig cfg = new SocketConnectorConfig();
cfg.setConnectTimeout(CONNECT_TIMEOUT);
if (USE_CUSTOM_CODEC) {
cfg.getFilterChain().addLast(
"codec",
new ProtocolCodecFilter(
new SumUpProtocolCodecFactory(false)));
} else {
cfg.getFilterChain().addLast(
"codec",
new ProtocolCodecFilter(
new ObjectSerializationCodecFactory()));
}
cfg.getFilterChain().addLast("logger", new LoggingFilter());
IoSession session;
for (;;) {
try {
ConnectFuture future = connector.connect(new InetSocketAddress(
HOSTNAME, PORT), new ClientSessionHandler(values), cfg);
future.join();
session = future.getSession();
break;