Search in sources :

Example 1 with SctpServerChannel

use of io.netty.channel.sctp.SctpServerChannel 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();
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) SctpChannel(io.netty.channel.sctp.SctpChannel) LoggingHandler(io.netty.handler.logging.LoggingHandler) InetSocketAddress(java.net.InetSocketAddress) NioSctpServerChannel(io.netty.channel.sctp.nio.NioSctpServerChannel) SctpServerChannel(io.netty.channel.sctp.SctpServerChannel) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) NioSctpServerChannel(io.netty.channel.sctp.nio.NioSctpServerChannel) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) SctpEchoServerHandler(io.netty.example.sctp.SctpEchoServerHandler) InetAddress(java.net.InetAddress) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Aggregations

ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1 ChannelFuture (io.netty.channel.ChannelFuture)1 EventLoopGroup (io.netty.channel.EventLoopGroup)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 SctpChannel (io.netty.channel.sctp.SctpChannel)1 SctpServerChannel (io.netty.channel.sctp.SctpServerChannel)1 NioSctpServerChannel (io.netty.channel.sctp.nio.NioSctpServerChannel)1 SctpEchoServerHandler (io.netty.example.sctp.SctpEchoServerHandler)1 LoggingHandler (io.netty.handler.logging.LoggingHandler)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1