use of io.netty.example.sctp.SctpEchoServerHandler in project netty by netty.
the class SctpMultiHomingEchoServer method main.
public static void main(String[] args) throws Exception {
// Configure the server.
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup).channel(NioSctpServerChannel.class).option(ChannelOption.SO_BACKLOG, 100).handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ChannelInitializer<SctpChannel>() {
@Override
public void initChannel(SctpChannel ch) throws Exception {
ch.pipeline().addLast(// new LoggingHandler(LogLevel.INFO),
new SctpEchoServerHandler());
}
});
InetSocketAddress localAddress = SocketUtils.socketAddress(SERVER_PRIMARY_HOST, SERVER_PORT);
InetAddress localSecondaryAddress = SocketUtils.addressByName(SERVER_SECONDARY_HOST);
// Bind the server to primary address.
ChannelFuture bindFuture = b.bind(localAddress).sync();
//Get the underlying sctp channel
SctpServerChannel channel = (SctpServerChannel) bindFuture.channel();
//Bind the secondary address
ChannelFuture connectFuture = channel.bindAddress(localSecondaryAddress).sync();
// Wait until the connection is closed.
connectFuture.channel().closeFuture().sync();
} finally {
// Shut down all event loops to terminate all threads.
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
Aggregations