I'm attempting to wrestle into this submission, and still not having a lot of luck.
Doing essentially the same thing as Jestan's example, I get the AlreadyBoundException below. Specifically, I call bind(new InetSocketAddress("localhost", 0)) to for the local socket. Then iterate the association addresses and call channel.bindAddress() for each host. Then bootstrap.remoteAddress(primary), followed by bootstrap.connect().
This is all a little baffling - particularly the fact that the API doesn't entirely make sense (or maybe I'm seriously misusing it). At the moment I'm just writing a test which will start two servers, and then start a client that will have an association with both servers' addresses. For that, I'm iterating the NICs, and wind up with an association with my network address + 127.0.0.1 for the client. In the test, I send data across the connection, and verify that it's been received - then shut down the primary server, and test that data is still received by the secondary one - i.e. failover using SCTP works.
But what's mysterious is that channel.bindAddress() does not take a port - so if I wanted an association that contained two hostnames and ports, it's not clear that that's possible. I work around it by using the loopback interface plus the machine's NIC's addresses in my test - and I suppose you could just run a server on multiple hosts but the same port - but that seems like a bizarre restriction.
Maybe what I'm looking for is SctpMultiChannel (which has no analogue in Netty)? Or maybe it's a misuse of SCTP to try to do that?
At any rate, I'd settle for knowing why bindAddress() is failing for now.
java.nio.channels.AlreadyBoundException
at sun.nio.ch.sctp.SctpNet.throwAlreadyBoundException(SctpNet.java:59)
at sun.nio.ch.sctp.SctpChannelImpl.bindUnbindAddress(SctpChannelImpl.java:243)
at sun.nio.ch.sctp.SctpChannelImpl.bindAddress(SctpChannelImpl.java:209)
at io.netty.channel.sctp.nio.NioSctpChannel.bindAddress(NioSctpChannel.java:352)
at io.netty.channel.sctp.nio.NioSctpChannel$1.run(NioSctpChannel.java:361)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:343)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
at io.netty.util.concurrent.SingleThreadEventExecutor$3.run(SingleThreadEventExecutor.java:131)
at io.netty.util.internal.chmv8.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1412)
at io.netty.util.internal.chmv8.ForkJoinTask.doExec(ForkJoinTask.java:280)
at io.netty.util.internal.chmv8.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:877)
at io.netty.util.internal.chmv8.ForkJoinPool.scan(ForkJoinPool.java:1706)
at io.netty.util.internal.chmv8.ForkJoinPool.runWorker(ForkJoinPool.java:1661)
at io.netty.util.internal.chmv8.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:126)
-Tim