本文整理汇总了Java中com.sun.nio.sctp.SctpMultiChannel.open方法的典型用法代码示例。如果您正苦于以下问题:Java SctpMultiChannel.open方法的具体用法?Java SctpMultiChannel.open怎么用?Java SctpMultiChannel.open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.nio.sctp.SctpMultiChannel
的用法示例。
在下文中一共展示了SctpMultiChannel.open方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doTest
import com.sun.nio.sctp.SctpMultiChannel; //导入方法依赖的package包/类
void doTest(SocketAddress peerAddress) {
SctpMultiChannel channel = null;
ByteBuffer buffer = ByteBuffer.allocate(Util.LARGE_BUFFER);
MessageInfo info = MessageInfo.createOutgoing(null, 0);
try {
channel = SctpMultiChannel.open();
/* setup an association implicitly by sending a small message */
int streamNumber = 0;
debug("sending to " + peerAddress + " on stream number: " + streamNumber);
info = MessageInfo.createOutgoing(peerAddress, streamNumber);
buffer.put(Util.SMALL_MESSAGE.getBytes("ISO-8859-1"));
buffer.flip();
int position = buffer.position();
int remaining = buffer.remaining();
debug("sending small message: " + buffer);
int sent = channel.send(buffer, info);
check(sent == remaining, "sent should be equal to remaining");
check(buffer.position() == (position + sent),
"buffers position should have been incremented by sent");
/* Receive the COMM_UP */
buffer.clear();
BranchNotificationHandler handler = new BranchNotificationHandler();
info = channel.receive(buffer, null, handler);
check(handler.receivedCommUp(), "COMM_UP no received");
Set<Association> associations = channel.associations();
check(!associations.isEmpty(),"There should be some associations");
Association bassoc = associations.iterator().next();
/* TEST 1: branch */
SctpChannel bchannel = channel.branch(bassoc);
check(!bchannel.getAllLocalAddresses().isEmpty(),
"branched channel should be bound");
check(!bchannel.getRemoteAddresses().isEmpty(),
"branched channel should be connected");
check(channel.associations().isEmpty(),
"there should be no associations since the only one was branched off");
buffer.clear();
info = bchannel.receive(buffer, null, null);
buffer.flip();
check(info != null, "info is null");
check(info.streamNumber() == streamNumber,
"message not sent on the correct stream");
check(info.bytes() == Util.SMALL_MESSAGE.getBytes("ISO-8859-1").
length, "bytes received not equal to message length");
check(info.bytes() == buffer.remaining(), "bytes != remaining");
check(Util.compare(buffer, Util.SMALL_MESSAGE),
"received message not the same as sent message");
} catch (IOException ioe) {
unexpected(ioe);
} finally {
clientFinishedLatch.countDown();
try { serverFinishedLatch.await(10L, TimeUnit.SECONDS); }
catch (InterruptedException ie) { unexpected(ie); }
if (channel != null) {
try { channel.close(); }
catch (IOException e) { unexpected (e);}
}
}
}