当前位置: 首页>>代码示例>>Java>>正文


Java SctpMultiChannel.open方法代码示例

本文整理汇总了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);}
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:68,代码来源:Branch.java


注:本文中的com.sun.nio.sctp.SctpMultiChannel.open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。