Search in sources :

Example 71 with DatagramChannel

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

the class DatagramChannelMulticastTest method test_open.

public void test_open() throws IOException {
    DatagramChannel dc = DatagramChannel.open();
    // Unlike MulticastSocket, DatagramChannel has SO_REUSEADDR set to false by default.
    assertFalse(dc.getOption(StandardSocketOptions.SO_REUSEADDR));
    assertNull(dc.getLocalAddress());
    assertTrue(dc.isOpen());
    assertFalse(dc.isConnected());
}
Also used : DatagramChannel(java.nio.channels.DatagramChannel)

Example 72 with DatagramChannel

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

the class DatagramChannelMulticastTest method test_block_wildcardAddress.

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

Example 73 with DatagramChannel

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

the class DatagramChannelMulticastTest method test_joinSourceSpecific_afterClose.

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

Example 74 with DatagramChannel

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

the class DatagramChannelMulticastTest method test_joinSourceSpecific_nonMulticastGroupAddress_IPv6.

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

Example 75 with DatagramChannel

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

the class DatagramChannelMulticastTest method test_joinSourceSpecific_nonMulticastGroupAddress_IPv4.

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

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