List of usage examples for io.netty.channel.sctp SctpChannel bindAddress
ChannelFuture bindAddress(InetAddress localAddress);
From source file:com.cmz.sctp.multihoming.SctpMultiHomingEchoClient.java
License:Apache License
public static void main(String[] args) throws Exception { // Configure the client. EventLoopGroup group = new NioEventLoopGroup(); try {/*from w w w.ja va 2 s . c o m*/ 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(); } }
From source file:com.hop.hhxx.example.sctp.multihoming.SctpMultiHomingEchoClient.java
License:Apache License
public static void main(String[] args) throws Exception { // Configure the client. EventLoopGroup group = new NioEventLoopGroup(); try {/*from www .ja v a2s .c o m*/ 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 = new InetSocketAddress(CLIENT_PRIMARY_HOST, CLIENT_PORT); InetAddress localSecondaryAddress = InetAddress.getByName(CLIENT_SECONDARY_HOST); InetSocketAddress remoteAddress = new InetSocketAddress(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(); } }
From source file:org.mobicents.protocols.sctp.netty.NettyAssociationImpl.java
License:Open Source License
protected void connect() { if (!this.started || this.up) { // return if not started or already up return;/*from w w w . ja va2 s .c o m*/ } if (logger.isDebugEnabled()) { logger.debug(String.format("Initiating connection started: Association=%s", this)); } Bootstrap b; InetSocketAddress localAddress; try { EventLoopGroup group = this.management.getBossGroup(); b = new Bootstrap(); b.group(group); if (this.ipChannelType == IpChannelType.SCTP) { b.channel(NioSctpChannel.class); // applying of stack level SCTP options this.applySctpOptions(b); b.handler(new NettySctpClientChannelInitializer(this)); } else { b.channel(NioSocketChannel.class); b.option(ChannelOption.TCP_NODELAY, true); b.handler(new NettyTcpClientChannelInitializer(this)); } localAddress = new InetSocketAddress(this.hostAddress, this.hostPort); } catch (Exception e) { logger.error(String.format("Exception while creating connection for Association=%s", this.getName()), e); this.scheduleConnect(); return; } // Bind the client channel. try { ChannelFuture bindFuture = b.bind(localAddress).sync(); Channel channel = bindFuture.channel(); if (this.ipChannelType == IpChannelType.SCTP) { // Get the underlying sctp channel SctpChannel sctpChannel = (SctpChannel) 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 if (this.extraHostAddresses != null) { for (int count = 0; count < this.extraHostAddresses.length; count++) { String localSecondaryAddress = this.extraHostAddresses[count]; InetAddress localSecondaryInetAddress = InetAddress.getByName(localSecondaryAddress); sctpChannel.bindAddress(localSecondaryInetAddress).sync(); } } } InetSocketAddress remoteAddress = new InetSocketAddress(this.peerAddress, this.peerPort); // Finish connect bindFuture.channel().connect(remoteAddress); if (logger.isDebugEnabled()) { logger.debug(String.format("Initiating connection scheduled: Association=%s remoteAddress=%s", this, remoteAddress)); } } catch (Exception e) { logger.error(String.format("Exception while finishing connection for Association=%s", this.getName()), e); } }