Search in sources :

Example 76 with DatagramChannel

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

the class DatagramChannelMulticastTest method checkMembershipKeyAccessors.

private void checkMembershipKeyAccessors(InetAddress group, NetworkInterface networkInterface) throws Exception {
    if (!supportsMulticast) {
        return;
    }
    DatagramChannel dc = createReceiverChannel();
    MembershipKey key = dc.join(group, networkInterface);
    assertSame(dc, key.channel());
    assertSame(group, key.group());
    assertTrue(key.isValid());
    assertSame(networkInterface, key.networkInterface());
    assertNull(key.sourceAddress());
    dc.close();
}
Also used : DatagramChannel(java.nio.channels.DatagramChannel) MembershipKey(java.nio.channels.MembershipKey)

Example 77 with DatagramChannel

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

the class DatagramChannelMulticastTest method test_joinAnySource_nullNetworkInterface.

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

Example 78 with DatagramChannel

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

the class DatagramChannelMulticastTest method test_joinSourceSpecific_mixedAddressTypes.

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

Example 79 with DatagramChannel

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

the class DatagramChannelMulticastTest method test_joinAnySource_processLimit.

public void test_joinAnySource_processLimit() throws Exception {
    if (!supportsMulticast) {
        return;
    }
    DatagramChannel dc = createReceiverChannel();
    for (byte i = 1; i <= 25; i++) {
        InetAddress groupAddress = Inet4Address.getByName("239.255.0." + i);
        try {
            dc.join(groupAddress, ipv4NetworkInterface);
        } catch (SocketException e) {
            // There is a limit, that's ok according to the RI docs. For this test a lower bound of 20
            // is used, which appears to be the default linux limit.
            // See /proc/sys/net/ipv4/igmp_max_memberships
            assertTrue(i > 20);
            break;
        }
    }
    dc.close();
}
Also used : SocketException(java.net.SocketException) DatagramChannel(java.nio.channels.DatagramChannel) InetAddress(java.net.InetAddress)

Example 80 with DatagramChannel

use of java.nio.channels.DatagramChannel 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)

Aggregations

DatagramChannel (java.nio.channels.DatagramChannel)211 InetSocketAddress (java.net.InetSocketAddress)91 ByteBuffer (java.nio.ByteBuffer)71 IOException (java.io.IOException)57 DatagramSocket (java.net.DatagramSocket)21 SocketAddress (java.net.SocketAddress)21 MembershipKey (java.nio.channels.MembershipKey)21 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)20 SocketChannel (java.nio.channels.SocketChannel)17 SelectionKey (java.nio.channels.SelectionKey)16 InetAddress (java.net.InetAddress)13 Selector (java.nio.channels.Selector)13 Test (org.junit.Test)11 SocketException (java.net.SocketException)9 ClosedChannelException (java.nio.channels.ClosedChannelException)9 Histogram (org.HdrHistogram.Histogram)8 CancelledKeyException (java.nio.channels.CancelledKeyException)7 DatagramPacket (java.net.DatagramPacket)5 NetworkInterface (java.net.NetworkInterface)5 ArrayList (java.util.ArrayList)5