Search in sources :

Example 11 with MembershipKey

use of java.nio.channels.MembershipKey in project j2objc by google.

the class DatagramChannelMulticastTest method test_block_null.

public void test_block_null() throws Exception {
    if (!supportsMulticast) {
        return;
    }
    DatagramChannel dc = createReceiverChannel();
    MembershipKey membershipKey = dc.join(GOOD_MULTICAST_IPv4, ipv4NetworkInterface);
    try {
        membershipKey.block(null);
        fail();
    } catch (NullPointerException expected) {
    }
    dc.close();
}
Also used : DatagramChannel(java.nio.channels.DatagramChannel) MembershipKey(java.nio.channels.MembershipKey)

Example 12 with MembershipKey

use of java.nio.channels.MembershipKey in project j2objc by google.

the class DatagramChannelMulticastTest method test_join_canMixTypesOnDifferentInterfaces.

/**
 * Confirms that the scope of each membership is network interface-level.
 */
public void test_join_canMixTypesOnDifferentInterfaces() throws Exception {
    if (!supportsMulticast) {
        return;
    }
    DatagramChannel dc = DatagramChannel.open();
    MembershipKey membershipKey1 = dc.join(GOOD_MULTICAST_IPv4, ipv4NetworkInterface);
    MembershipKey membershipKey2 = dc.join(GOOD_MULTICAST_IPv4, loopbackInterface, UNICAST_IPv4_1);
    assertNotSame(membershipKey1, membershipKey2);
    dc.close();
}
Also used : DatagramChannel(java.nio.channels.DatagramChannel) MembershipKey(java.nio.channels.MembershipKey)

Example 13 with MembershipKey

use of java.nio.channels.MembershipKey in project JGroups by belaban.

the class MulticastTest method testDatagramChannel.

protected static void testDatagramChannel() throws IOException {
    NetworkInterface ni = NetworkInterface.getByInetAddress(InetAddress.getLocalHost());
    DatagramChannel dc = DatagramChannel.open(StandardProtocolFamily.INET).setOption(StandardSocketOptions.SO_REUSEADDR, true).bind(new InetSocketAddress(PORT)).setOption(StandardSocketOptions.IP_MULTICAST_IF, ni);
    MembershipKey key = dc.join(group, ni);
    System.out.println("key = " + key);
}
Also used : DatagramChannel(java.nio.channels.DatagramChannel) MembershipKey(java.nio.channels.MembershipKey)

Example 14 with MembershipKey

use of java.nio.channels.MembershipKey in project j2objc by google.

the class DatagramChannelMulticastTest method test_unblock_mixedAddressTypes_IPv6.

public void test_unblock_mixedAddressTypes_IPv6() throws Exception {
    if (!supportsMulticast) {
        return;
    }
    DatagramChannel dc = createReceiverChannel();
    MembershipKey membershipKey = dc.join(GOOD_MULTICAST_IPv6, ipv6NetworkInterface);
    try {
        membershipKey.unblock(UNICAST_IPv4_1);
        fail();
    } catch (IllegalStateException expected) {
    // Either of these exceptions are fine
    } catch (IllegalArgumentException expected) {
    // Either of these exceptions are fine
    }
    dc.close();
}
Also used : DatagramChannel(java.nio.channels.DatagramChannel) MembershipKey(java.nio.channels.MembershipKey)

Example 15 with MembershipKey

use of java.nio.channels.MembershipKey in project j2objc by google.

the class DatagramChannelMulticastTest method test_block_mixedAddressTypes_IPv6.

public void test_block_mixedAddressTypes_IPv6() throws Exception {
    if (!supportsMulticast) {
        return;
    }
    DatagramChannel dc = createReceiverChannel();
    MembershipKey membershipKey = dc.join(GOOD_MULTICAST_IPv6, ipv6NetworkInterface);
    try {
        membershipKey.block(UNICAST_IPv4_1);
        fail();
    } catch (IllegalArgumentException expected) {
    }
    dc.close();
}
Also used : DatagramChannel(java.nio.channels.DatagramChannel) MembershipKey(java.nio.channels.MembershipKey)

Aggregations

MembershipKey (java.nio.channels.MembershipKey)25 DatagramChannel (java.nio.channels.DatagramChannel)22 SuppressJava6Requirement (io.netty.util.internal.SuppressJava6Requirement)3 InetAddress (java.net.InetAddress)2 InetSocketAddress (java.net.InetSocketAddress)2 ByteBuffer (java.nio.ByteBuffer)2 IOException (java.io.IOException)1 SocketException (java.net.SocketException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1