`
Donald_Draper
  • 浏览: 953142 次
社区版块
存档分类
最新评论

MulticastChanne接口定义

    博客分类:
  • NIO
nio 
阅读更多
NetworkChannel接口定义:http://donald-draper.iteye.com/blog/2369773
MembershipKey定义:http://donald-draper.iteye.com/blog/2372947
package java.nio.channels;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.io.IOException;
import java.net.ProtocolFamily;             // javadoc
import java.net.StandardProtocolFamily;     // javadoc
import java.net.StandardSocketOptions;      // javadoc

/**
 * A network channel that supports Internet Protocol (IP) multicasting.
 *MulticastChannel是一个支持多播网络IP协议的网络通道
 *  IP multicasting is the transmission of IP datagrams to members of
 * a [i]group[/i] that is zero or more hosts identified by a single destination
 * address.
 *IP多播是传输IP报文到多播组目的地址的一个或多个主机。
 * <p> In the case of a channel to an {@link StandardProtocolFamily#INET IPv4} socket,
 * the underlying operating system supports <a href="http://www.ietf.org/rfc/rfc2236.txt">
 * <i>RFC 2236: Internet Group Management Protocol, Version 2 (IGMPv2)</i></a>.
 * It may optionally support source filtering as specified by <a
 * href="http://www.ietf.org/rfc/rfc3376.txt"> <i>RFC 3376: Internet Group
 * Management Protocol, Version 3 (IGMPv3)</i></a>.
 * For channels to an {@link StandardProtocolFamily#INET6 IPv6} socket, the equivalent
 * standards are <a href="http://www.ietf.org/rfc/rfc2710.txt"> <i>RFC 2710:
 * Multicast Listener Discovery (MLD) for IPv6</i></a> and <a
 * href="http://www.ietf.org/rfc/rfc3810.txt"> <i>RFC 3810: Multicast Listener
 * Discovery Version 2 (MLDv2) for IPv6</i></a>.
 *
 一个ip4的socket网络通道底层支持IGMPv2,可以源地址过滤的IGMPv3。一个IPv6的socket网络通道
 ,对应的为MLD,MLDv2。

 * <p> The {@link #join(InetAddress,NetworkInterface)} method is used to
 * join a group and receive all multicast datagrams sent to the group. A channel
 * may join several multicast groups and may join the same group on several
 * {@link NetworkInterface interfaces}. Membership is dropped by invoking the {@link
 * MembershipKey#drop drop} method on the returned {@link MembershipKey}. If the
 * underlying platform supports source filtering then the {@link MembershipKey#block
 * block} and {@link MembershipKey#unblock unblock} methods can be used to block or
 * unblock multicast datagrams from particular source addresses.
 *join(InetAddress,NetworkInterface)方法加入一个多播组,接受发送到多播组的报文。
一个多播通道可以加入多个多播分组,或加入多个网卡接口的相同多播分组。调用MembershipKey的
drop方法,将会丢弃Membership,即MembershipKey无效。如果底层操作系统支持源地址过滤,则
可以调用MembershipKey#block和#unblock方法,用于阻塞从特殊源地址的报文或解除从特殊源地址的报文阻塞。
 * <p> The {@link #join(InetAddress,NetworkInterface,InetAddress)} method
 * is used to begin receiving datagrams sent to a group whose source address matches
 * a given source address. This method throws {@link UnsupportedOperationException}
 * if the underlying platform does not support source filtering.  Membership is
 * [i]cumulative[/i] and this method may be invoked again with the same group
 * and interface to allow receiving datagrams from other source addresses. The
 * method returns a {@link MembershipKey} that represents membership to receive
 * datagrams from the given source address. Invoking the key's {@link
 * MembershipKey#drop drop} method drops membership so that datagrams from the
 * source address can no longer be received.
 *#join(InetAddress,NetworkInterface,InetAddress)方法为,加入一个多播组,
 开始接受发送到多播组的源地址报文。如果底层平台不支持源地址过滤,则抛出UnsupportedOperationException。
多播组成员关系是可以累加的,,此方法以相同的多播地址和网络接口参数可以多次调用,
即允许接受多个源地址发送到多播组的报文。此方法返回一个表示接受指定源地址报文的多播关系key。
调用MembershipKey#drop方法,将解除多播成员关系,即不在接受源地址发送的多播报文。
 * <h4>Platform dependencies</h4>
 *平台依赖性
 * The multicast implementation is intended to map directly to the native
 * multicasting facility. Consequently, the following items should be considered
 * when developing an application that receives IP multicast datagrams:
 *多播的实现是需要直接映射到本地的多播硬件设备。因此在开发一个接受多播ip的报文时,
 需要考虑一下几条:
 * [list=1]
 *
 * <li><p> The creation of the channel should specify the {@link ProtocolFamily}
 * that corresponds to the address type of the multicast groups that the channel
 * will join. There is no guarantee that a channel to a socket in one protocol
 * family can join and receive multicast datagrams when the address of the
 * multicast group corresponds to another protocol family. For example, it is
 * implementation specific if a channel to an {@link StandardProtocolFamily#INET6 IPv6}
 * socket can join an {@link StandardProtocolFamily#INET IPv4} multicast group and receive
 * multicast datagrams sent to the group. 
</li>
 *通道创建时应该确定通道加入的多播组地址类型的ProtocolFamily。多播通道不能保证,
 一个ProtocolFamily类型的socket可以接受另外一个ProtocolFamily类型的多播组报文,或者说
 不能保证能加入另外一个ProtocolFamily类型多播组。比如通道的socket的协议组为StandardProtocolFamily#INET6 IPv6
 ,而加入的多播组为StandardProtocolFamily#INET IPv4。这段话的含义为,通道在创建关联一个
 协议ProtocolFamily,具体的协议通道,只能加入相应的多播协议组。及INET6通道只能加入ip6地址多播组,
INET通道只能加入ip4地址多播组。

//DatagramChannel,打开一个指定协议的报文通道
public static DatagramChannel open(ProtocolFamily family) throws IOException {
        return SelectorProvider.provider().openDatagramChannel(family);
    }
 * <li> The channel's socket should be bound to the {@link
 * InetAddress#isAnyLocalAddress wildcard} address. If the socket is bound to
 * a specific address, rather than the wildcard address then it is implementation
 * specific if multicast datagrams are received by the socket. 
</li>
 *通道应该绑定一个本地地址。如果绑定为一个特定的地址,而不是本地地址,具体的通道实现
 需要确定是否多播报文可以通过socket接受。
 * <li> The {@link StandardSocketOptions#SO_REUSEADDR SO_REUSEADDR} option should be
 * enabled prior to {@link NetworkChannel#bind binding} the socket. This is
 * required to allow multiple members of the group to bind to the same
 * address. 
</li>
 *StandardSocketOptions#SO_REUSEADDR应该在地址绑定前,配置地址重用选项。
 以便多个成员能够绑定同样的地址,加入多播组。
 * [/list]
 *
 * <p> <b>Usage Example:</b>
 * <pre>使用实例
 *     // join multicast group on this interface, and also use this
 *     // interface for outgoing multicast datagrams
       加入一个指定网卡的多播组,同时用这个网卡发送多播报文
 *     NetworkInterface ni = NetworkInterface.getByName("hme0");
 *
 *     DatagramChannel dc = DatagramChannel.open(StandardProtocolFamily.INET)
 *         .setOption(StandardSocketOptions.SO_REUSEADDR, true)
 *         .bind(new InetSocketAddress(5000))
 *         .setOption(StandardSocketOptions.IP_MULTICAST_IF, ni);
 *
 *     InetAddress group = InetAddress.getByName("225.4.5.6");
 *
 *     MembershipKey key = dc.join(group, ni);
 * </pre>
 *
 * @since 1.7
 */
//多播通道
public interface MulticastChannel
    extends NetworkChannel
{
    /**
     * Closes this channel.
     *关闭通道
     * <p> If the channel is a member of a multicast group then the membership
     * is {@link MembershipKey#drop dropped}. Upon return, the {@link
     * MembershipKey membership-key} will be {@link MembershipKey#isValid
     * invalid}.
     *如果通道是一个多播组的成员,在通道关闭时,将会drop相应的MembershipKey。
     在方法执行后,MembershipKey将会无效
     * <p> This method otherwise behaves exactly as specified by the {@link
     * Channel} interface.
     *此方法在其他方面与通道接口相似。
     * @throws  IOException
     *          If an I/O error occurs
     */
    @Override void close() throws IOException;

    /**
     * Joins a multicast group to begin receiving all datagrams sent to the group,
     * returning a membership key.
     *加入一个多播组,开始接受发送到多播组的报文,返回MembershipKey。
     * <p> If this channel is currently a member of the group on the given
     * interface to receive all datagrams then the membership key, representing
     * that membership, is returned. Otherwise this channel joins the group and
     * the resulting new membership key is returned. The resulting membership key
     * is not {@link MembershipKey#sourceAddress source-specific}.
     *如果为指定网络接口地址的组成员,正在接受所有报文,将返回表示成员关系的MembershipKey。
     否则通道加入分组,创建一个新的MembershipKey返回。MembershipKey的源地址是不确定的。
     * <p> A multicast channel may join several multicast groups, including
     * the same group on more than one interface. An implementation may impose a
     * limit on the number of groups that may be joined at the same time.
     *一个多播通道可以加入多个多播分组,包括在一个或多个网络接口上的相同分组。一个具体
     的实现也许会限制同一时间加入多播组的数量。
     * @param   group
     *          The multicast address to join
     * @param   interf
     *          The network interface on which to join the group
     *
     * @return  The membership key
     *
     * @throws  IllegalArgumentException,多播组地址为非多播地址,或通道不支持多播组地址参数
     *          If the group parameter is not a {@link InetAddress#isMulticastAddress
     *          multicast} address, or the group parameter is an address type
     *          that is not supported by this channel
     * @throws  IllegalStateException,如果通道已经加入源地址确定的对应的网络接口上的多播组
     *          If the channel already has source-specific membership of the
     *          group on the interface
     * @throws  UnsupportedOperationException 如果通道不是一个网络写socket
     *          If the channel's socket is not an Internet Protocol socket
     * @throws  ClosedChannelException
     *          If this channel is closed
     * @throws  IOException
     *          If an I/O error occurs
     * @throws  SecurityException
     *          If a security manager is set, and its
     *          {@link SecurityManager#checkMulticast(InetAddress) checkMulticast}
     *          method denies access to the multiast group
     */
    MembershipKey join(InetAddress group, NetworkInterface interf)
        throws IOException;

    /**
     * Joins a multicast group to begin receiving datagrams sent to the group
     * from a given source address.
     *加入一个多播组,开始接受发送到多播组的源地址报文,返回MembershipKey。
     * <p> If this channel is currently a member of the group on the given
     * interface to receive datagrams from the given source address then the
     * membership key, representing that membership, is returned. Otherwise this
     * channel joins the group and the resulting new membership key is returned.
     * The resulting membership key is {@link MembershipKey#sourceAddress
     * source-specific}.
     *如果为指定网络接口地址的组成员,正在接受所有源地址的报文,将返回表示成员关系的MembershipKey。
     否则通道加入分组,创建一个新的MembershipKey返回。MembershipKey的源地址是确定的。
     * <p> Membership is [i]cumulative[/i] and this method may be invoked
     * again with the same group and interface to allow receiving datagrams sent
     * by other source addresses to the group.
     *多播组成员关系是可以累加的,此方法以相同的多播地址和网络接口参数可以多次调用,
     即允许从多个源地址发送报文到多播组。
     * @param   group
     *          The multicast address to join
     * @param   interf
     *          The network interface on which to join the group
     * @param   source
     *          The source address
     *
     * @return  The membership key
     *
     * @throws  IllegalArgumentException
     *          If the group parameter is not a {@link
     *          InetAddress#isMulticastAddress multicast} address, the
     *          source parameter is not a unicast address, the group
     *          parameter is an address type that is not supported by this channel,
     *          or the source parameter is not the same address type as the group
     * @throws  IllegalStateException
     *          If the channel is currently a member of the group on the given
     *          interface to receive all datagrams
     * @throws  UnsupportedOperationException
     *          If the channel's socket is not an Internet Protocol socket or
     *          source filtering is not supported
     * @throws  ClosedChannelException
     *          If this channel is closed
     * @throws  IOException
     *          If an I/O error occurs
     * @throws  SecurityException
     *          If a security manager is set, and its
     *          {@link SecurityManager#checkMulticast(InetAddress) checkMulticast}
     *          method denies access to the multiast group
     */
    MembershipKey join(InetAddress group, NetworkInterface interf, InetAddress source)
        throws IOException;
}
0
1
分享到:
评论

相关推荐

    五子棋wuziq.zip

    五子棋游戏想必大家都非常熟悉,游戏规则十分简单。游戏开始后,玩家在游戏设置中选择人机对战,则系统执黑棋,玩家自己执白棋。双方轮流下一棋,先将横、竖或斜线的5个或5个以上同色棋子连成不间断的一排者为胜。 【项目资源】:包含前端、后端、移动开发、操作系统、人工智能、物联网、信息化管理、数据库、硬件开发、大数据、课程资源、音视频、网站开发等各种技术项目的源码。包括STM32、ESP8266、PHP、QT、Linux、iOS、C++、Java、python、web、C#、EDA、proteus、RTOS等项目的源码。 【技术】 Java、Python、Node.js、Spring Boot、Django、Express、MySQL、PostgreSQL、MongoDB、React、Angular、Vue、Bootstrap、Material-UI、Redis、Docker、Kubernetes

    单片机C语言Proteus仿真实例占空比可调模拟仿真程序

    单片机C语言Proteus仿真实例占空比可调模拟仿真程序提取方式是百度网盘分享地址

    单片机C语言Proteus仿真实例用数码管设计的可调式电子钟

    单片机C语言Proteus仿真实例用数码管设计的可调式电子钟提取方式是百度网盘分享地址

    2023年第16届中国大学生计算机设计大赛附往届获奖作品合集资料

    2023年第16届中国大学生计算机设计大赛附往届获奖作品合集资料提取方式是百度网盘分享地址

    Linux下,C语言实现五子棋程序Linux-Wuziqi.zip

    五子棋游戏想必大家都非常熟悉,游戏规则十分简单。游戏开始后,玩家在游戏设置中选择人机对战,则系统执黑棋,玩家自己执白棋。双方轮流下一棋,先将横、竖或斜线的5个或5个以上同色棋子连成不间断的一排者为胜。 【项目资源】:包含前端、后端、移动开发、操作系统、人工智能、物联网、信息化管理、数据库、硬件开发、大数据、课程资源、音视频、网站开发等各种技术项目的源码。包括STM32、ESP8266、PHP、QT、Linux、iOS、C++、Java、python、web、C#、EDA、proteus、RTOS等项目的源码。 【技术】 Java、Python、Node.js、Spring Boot、Django、Express、MySQL、PostgreSQL、MongoDB、React、Angular、Vue、Bootstrap、Material-UI、Redis、Docker、Kubernetes

    需要系数法负荷计算软件.zip

    需要系数法负荷计算软件

    变压器差动计算软件.zip

    变压器差动计算软件

    单片机C语言Proteus仿真实例数码管动态显示

    单片机C语言Proteus仿真实例数码管动态显示提取方式是百度网盘分享地址

    Python源码-小海龟之螺旋曲线.py

    Python源码-小海龟之螺旋曲线

    Python源码-图形验证码考眼力游戏.py

    Python源码-图形验证码考眼力游戏

    飞机大战项目planegame.zip

    五子棋游戏想必大家都非常熟悉,游戏规则十分简单。游戏开始后,玩家在游戏设置中选择人机对战,则系统执黑棋,玩家自己执白棋。双方轮流下一棋,先将横、竖或斜线的5个或5个以上同色棋子连成不间断的一排者为胜。 【项目资源】:包含前端、后端、移动开发、操作系统、人工智能、物联网、信息化管理、数据库、硬件开发、大数据、课程资源、音视频、网站开发等各种技术项目的源码。包括STM32、ESP8266、PHP、QT、Linux、iOS、C++、Java、python、web、C#、EDA、proteus、RTOS等项目的源码。 【技术】 Java、Python、Node.js、Spring Boot、Django、Express、MySQL、PostgreSQL、MongoDB、React、Angular、Vue、Bootstrap、Material-UI、Redis、Docker、Kubernetes

    架空送电线路导地线弧垂计算小软件.zip

    架空送电线路导地线弧垂计算小软件

    W25Q512数据手册

    W25Q512数据手册。The W25Q512JV (512M-bit) Serial Flash memory provides a storage solution for systems with limited space, pins and power. The 25Q series offers flexibility and performance well beyond ordinary Serial Flash devices. They are ideal for code shadowing to RAM, executing code directly from Dual/Quad SPI (XIP) and storing voice, text and data. The device operates on a single 2.7V to 3.6V power supply with current consumption as low as 1µA for power-down. All devices are offered in space-

    three.js应用篇(五)模型内第一视角漫游

    完整示例代码

    setuptools-1.3.1.zip

    Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。

    单片机C语言Proteus仿真实例数码管显示4×4键盘矩阵按键

    单片机C语言Proteus仿真实例数码管显示4×4键盘矩阵按键提取方式是百度网盘分享地址

    setuptools-46.3.0.zip

    Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、Pandas和Requests,极大地丰富了Python的应用领域,从数据科学到Web开发。Python库的丰富性是Python成为最受欢迎的编程语言之一的关键原因之一。这些库不仅为初学者提供了快速入门的途径,而且为经验丰富的开发者提供了强大的工具,以高效率、高质量地完成复杂任务。例如,Matplotlib和Seaborn库在数据可视化领域内非常受欢迎,它们提供了广泛的工具和技术,可以创建高度定制化的图表和图形,帮助数据科学家和分析师在数据探索和结果展示中更有效地传达信息。

    bloom filter , 递归 , 回溯 , 五子棋 , 迷宫 , 扫雷 , 贪吃蛇 , 消字 , 各种数据结构算法.zip

    五子棋游戏想必大家都非常熟悉,游戏规则十分简单。游戏开始后,玩家在游戏设置中选择人机对战,则系统执黑棋,玩家自己执白棋。双方轮流下一棋,先将横、竖或斜线的5个或5个以上同色棋子连成不间断的一排者为胜。 【项目资源】:包含前端、后端、移动开发、操作系统、人工智能、物联网、信息化管理、数据库、硬件开发、大数据、课程资源、音视频、网站开发等各种技术项目的源码。包括STM32、ESP8266、PHP、QT、Linux、iOS、C++、Java、python、web、C#、EDA、proteus、RTOS等项目的源码。 【技术】 Java、Python、Node.js、Spring Boot、Django、Express、MySQL、PostgreSQL、MongoDB、React、Angular、Vue、Bootstrap、Material-UI、Redis、Docker、Kubernetes

    附件1:证券公司及基金管理公司子公司资产证券化业务管理规定(修订稿).pdf

    附件1:证券公司及基金管理公司子公司资产证券化业务管理规定(修订稿).pdf

    信息可视化类广东省大学生计算机设计大赛三等奖追溯党史数看百年历程视频

    信息可视化类广东省大学生计算机设计大赛三等奖追溯党史数看百年历程视频提取方式是百度网盘分享地址

Global site tag (gtag.js) - Google Analytics