use of java.nio.channels.DatagramChannel in project j2objc by google.
the class DatagramChannelMulticastTest method createChannelAndSendMulticastMessage.
private static void createChannelAndSendMulticastMessage(InetAddress group, int port, String msg, NetworkInterface sendingInterface) throws IOException {
// Any datagram socket can send to a group. It does not need to have joined the group.
DatagramChannel dc = DatagramChannel.open();
BindableChannel channel = new BindableChannel(dc, sendingInterface);
channel.sendMulticastMessage(msg, new InetSocketAddress(group, port));
dc.close();
}
use of java.nio.channels.DatagramChannel in project j2objc by google.
the class DatagramChannelMulticastTest method test_joinSourceSpecific_nullSourceAddress_IPv4.
public void test_joinSourceSpecific_nullSourceAddress_IPv4() throws Exception {
if (!supportsMulticast) {
return;
}
DatagramChannel dc = createReceiverChannel();
try {
dc.join(GOOD_MULTICAST_IPv4, ipv4NetworkInterface, null);
fail();
} catch (NullPointerException expected) {
}
dc.close();
}
use of java.nio.channels.DatagramChannel 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();
}
use of java.nio.channels.DatagramChannel in project j2objc by google.
the class DatagramChannelTest method test_bind_unresolvedAddress.
public void test_bind_unresolvedAddress() throws IOException {
DatagramChannel dc = DatagramChannel.open();
try {
dc.socket().bind(new InetSocketAddress("unresolvedname", 31415));
fail();
} catch (IOException expected) {
}
assertTrue(dc.isOpen());
assertFalse(dc.isConnected());
dc.close();
}
use of java.nio.channels.DatagramChannel in project j2objc by google.
the class DatagramChannelTest method test_read_intoReadOnlyByteArrays.
/* J2ObjC removed: not supported by Junit 4.11 (https://github.com/google/j2objc/issues/1318).
@Rule
public ResourceLeakageDetector.LeakageDetectorRule guardRule =
ResourceLeakageDetector.getRule();
*/
public void test_read_intoReadOnlyByteArrays() throws Exception {
ByteBuffer readOnly = ByteBuffer.allocate(1).asReadOnlyBuffer();
try (DatagramSocket ds = new DatagramSocket(0);
DatagramChannel dc = DatagramChannel.open()) {
dc.connect(ds.getLocalSocketAddress());
try {
dc.read(readOnly);
fail();
} catch (IllegalArgumentException expected) {
}
try {
dc.read(new ByteBuffer[] { readOnly });
fail();
} catch (IllegalArgumentException expected) {
}
try {
dc.read(new ByteBuffer[] { readOnly }, 0, 1);
fail();
} catch (IllegalArgumentException expected) {
}
}
}
Aggregations