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


Java SocketOptions.IP_MULTICAST_IF属性代码示例

本文整理汇总了Java中java.net.SocketOptions.IP_MULTICAST_IF属性的典型用法代码示例。如果您正苦于以下问题:Java SocketOptions.IP_MULTICAST_IF属性的具体用法?Java SocketOptions.IP_MULTICAST_IF怎么用?Java SocketOptions.IP_MULTICAST_IF使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在java.net.SocketOptions的用法示例。


在下文中一共展示了SocketOptions.IP_MULTICAST_IF属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getOption

@Override
public Object getOption(int optID) throws SocketException {
    if (optID == SocketOptions.SO_TIMEOUT) {
        return Integer.valueOf(receiveTimeout);
    } else if (optID == SocketOptions.IP_TOS) {
        return Integer.valueOf(trafficClass);
    } else {
        // Call the native first so there will be
        // an exception if the socket if closed.
        Object result = netImpl.getSocketOption(fd, optID);
        if (optID == SocketOptions.IP_MULTICAST_IF
                && (netImpl.getSocketFlags() & MULTICAST_IF) != 0) {
            try {
                return InetAddress.getByAddress(ipaddress);
            } catch (UnknownHostException e) {
                return null;
            }
        }
        return result;
    }
}
 
开发者ID:mnhkahn,项目名称:cInterphone,代码行数:21,代码来源:PlainDatagramSocketImpl.java

示例2: getOption

public Object getOption(int optID) throws SocketException {
    if (optID == SocketOptions.SO_TIMEOUT) {
        return Integer.valueOf(receiveTimeout);
    } else if (optID == SocketOptions.IP_TOS) {
        return Integer.valueOf(trafficClass);
    } else {
        // Call the native first so there will be
        // an exception if the socket if closed.
        Object result = netImpl.getSocketOption(fd, optID);
        if (optID == SocketOptions.IP_MULTICAST_IF
                && (netImpl.getSocketFlags() & MULTICAST_IF) != 0) {
            try {
                return InetAddress.getByAddress(ipaddress);
            } catch (UnknownHostException e) {
                return null;
            }
        }
        return result;
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:20,代码来源:PlainDatagramSocketImpl.java

示例3: getSocketOptionErrno

private static Object getSocketOptionErrno(FileDescriptor fd, int option) throws ErrnoException, SocketException {
    switch (option) {
    case SocketOptions.IP_MULTICAST_IF:
        // This is IPv4-only.
        return Libcore.os.getsockoptInAddr(fd, IPPROTO_IP, IP_MULTICAST_IF);
    case SocketOptions.IP_MULTICAST_IF2:
        // This is IPv6-only.
        return Libcore.os.getsockoptInt(fd, IPPROTO_IPV6, IPV6_MULTICAST_IF);
    case SocketOptions.IP_MULTICAST_LOOP:
        // Since setting this from java.net always sets IPv4 and IPv6 to the same value,
        // it doesn't matter which we return.
        return booleanFromInt(Libcore.os.getsockoptInt(fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP));
    case IoBridge.JAVA_IP_MULTICAST_TTL:
        // Since setting this from java.net always sets IPv4 and IPv6 to the same value,
        // it doesn't matter which we return.
        return Libcore.os.getsockoptInt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS);
    case SocketOptions.IP_TOS:
        // Since setting this from java.net always sets IPv4 and IPv6 to the same value,
        // it doesn't matter which we return.
        return Libcore.os.getsockoptInt(fd, IPPROTO_IPV6, IPV6_TCLASS);
    case SocketOptions.SO_BROADCAST:
        return booleanFromInt(Libcore.os.getsockoptInt(fd, SOL_SOCKET, SO_BROADCAST));
    case SocketOptions.SO_KEEPALIVE:
        return booleanFromInt(Libcore.os.getsockoptInt(fd, SOL_SOCKET, SO_KEEPALIVE));
    case SocketOptions.SO_LINGER:
        StructLinger linger = Libcore.os.getsockoptLinger(fd, SOL_SOCKET, SO_LINGER);
        if (!linger.isOn()) {
            return false;
        }
        return linger.l_linger;
    case SocketOptions.SO_OOBINLINE:
        return booleanFromInt(Libcore.os.getsockoptInt(fd, SOL_SOCKET, SO_OOBINLINE));
    case SocketOptions.SO_RCVBUF:
        return Libcore.os.getsockoptInt(fd, SOL_SOCKET, SO_RCVBUF);
    case SocketOptions.SO_REUSEADDR:
        return booleanFromInt(Libcore.os.getsockoptInt(fd, SOL_SOCKET, SO_REUSEADDR));
    case SocketOptions.SO_SNDBUF:
        return Libcore.os.getsockoptInt(fd, SOL_SOCKET, SO_SNDBUF);
    case SocketOptions.SO_TIMEOUT:
        return (int) Libcore.os.getsockoptTimeval(fd, SOL_SOCKET, SO_RCVTIMEO).toMillis();
    case SocketOptions.TCP_NODELAY:
        return booleanFromInt(Libcore.os.getsockoptInt(fd, IPPROTO_TCP, TCP_NODELAY));
    default:
        throw new SocketException("Unknown socket option: " + option);
    }
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:46,代码来源:IoBridge.java


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