Search in sources :

Example 1 with SctpEchoClientHandler

use of io.netty.example.sctp.SctpEchoClientHandler in project netty by netty.

the class SctpMultiHomingEchoClient method main.

public static void main(String[] args) throws Exception {
    // Configure the client.
    EventLoopGroup group = new NioEventLoopGroup();
    try {
        Bootstrap b = new Bootstrap();
        b.group(group).channel(NioSctpChannel.class).option(SctpChannelOption.SCTP_NODELAY, true).handler(new ChannelInitializer<SctpChannel>() {

            @Override
            public void initChannel(SctpChannel ch) throws Exception {
                ch.pipeline().addLast(//                             new LoggingHandler(LogLevel.INFO),
                new SctpEchoClientHandler());
            }
        });
        InetSocketAddress localAddress = SocketUtils.socketAddress(CLIENT_PRIMARY_HOST, CLIENT_PORT);
        InetAddress localSecondaryAddress = SocketUtils.addressByName(CLIENT_SECONDARY_HOST);
        InetSocketAddress remoteAddress = SocketUtils.socketAddress(SERVER_REMOTE_HOST, SERVER_REMOTE_PORT);
        // Bind the client channel.
        ChannelFuture bindFuture = b.bind(localAddress).sync();
        // Get the underlying sctp channel
        SctpChannel channel = (SctpChannel) bindFuture.channel();
        // Bind the secondary address.
        // Please note that, bindAddress in the client channel should be done before connecting if you have not
        // enable Dynamic Address Configuration. See net.sctp.addip_enable kernel param
        channel.bindAddress(localSecondaryAddress).sync();
        // Finish connect
        ChannelFuture connectFuture = channel.connect(remoteAddress).sync();
        // Wait until the connection is closed.
        connectFuture.channel().closeFuture().sync();
    } finally {
        // Shut down the event loop to terminate all threads.
        group.shutdownGracefully();
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) NioSctpChannel(io.netty.channel.sctp.nio.NioSctpChannel) SctpChannel(io.netty.channel.sctp.SctpChannel) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) SctpEchoClientHandler(io.netty.example.sctp.SctpEchoClientHandler) InetSocketAddress(java.net.InetSocketAddress) Bootstrap(io.netty.bootstrap.Bootstrap) InetAddress(java.net.InetAddress) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Aggregations

Bootstrap (io.netty.bootstrap.Bootstrap)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 NioSctpChannel (io.netty.channel.sctp.nio.NioSctpChannel)1 SctpEchoClientHandler (io.netty.example.sctp.SctpEchoClientHandler)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1