// Set this to false to use object serialization instead of custom codec.
private static final boolean USE_CUSTOM_CODEC = true;
public static void main( String[] args ) throws Throwable
{
IoAcceptor acceptor = new SocketAcceptor();
// Prepare the service configuration.
SocketAcceptorConfig cfg = new SocketAcceptorConfig();
cfg.setReuseAddress( true );
if( USE_CUSTOM_CODEC )
{
cfg.getFilterChain().addLast(
"codec",
new ProtocolCodecFilter( new SumUpProtocolCodecFactory( true ) ) );
}
else
{
cfg.getFilterChain().addLast(
"codec",
new ProtocolCodecFilter( new ObjectSerializationCodecFactory() ) );
}
cfg.getFilterChain().addLast( "logger", new LoggingFilter() );
acceptor.bind(
new InetSocketAddress( SERVER_PORT ),
new ServerSessionHandler( ), cfg );
System.out.println( "Listening on port " + SERVER_PORT );
}