use of java.net.MulticastSocket in project jdk8u_jdk by JetBrains.
the class SocketPermissionTest method joinGroupMulticastTest.
@Test
public void joinGroupMulticastTest() throws Exception {
InetAddress group = InetAddress.getByName("229.227.226.221");
try (MulticastSocket s = new MulticastSocket(0)) {
int port = s.getLocalPort();
String addr = "localhost:" + port;
AccessControlContext acc = getAccessControlContext(new SocketPermission(addr, "listen,resolve"), new SocketPermission("229.227.226.221", "connect,accept"));
// Positive
AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
s.joinGroup(group);
s.leaveGroup(group);
return null;
}, acc);
// Negative
try {
AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
s.joinGroup(group);
s.leaveGroup(group);
fail("Expected SecurityException");
return null;
}, RESTRICTED_ACC);
} catch (SecurityException expected) {
}
}
}
use of java.net.MulticastSocket in project wildfly by wildfly.
the class ManagedSocketFactoryTest method createMulticastSocket.
@Test
public void createMulticastSocket() throws IOException {
MulticastSocket socket1 = mock(MulticastSocket.class);
MulticastSocket socket2 = mock(MulticastSocket.class);
MulticastSocket socket3 = mock(MulticastSocket.class);
MulticastSocket socket4 = mock(MulticastSocket.class);
SocketAddress address = new InetSocketAddress(InetAddress.getLocalHost(), 1);
when(this.manager.createMulticastSocket("test", new InetSocketAddress(0))).thenReturn(socket1);
when(this.manager.createMulticastSocket("test", new InetSocketAddress(1))).thenReturn(socket2);
when(this.manager.createMulticastSocket("test", address)).thenReturn(socket3);
when(this.manager.createMulticastSocket("test")).thenReturn(socket4);
MulticastSocket result1 = this.subject.createMulticastSocket("test");
MulticastSocket result2 = this.subject.createMulticastSocket("test", 1);
MulticastSocket result3 = this.subject.createMulticastSocket("test", address);
MulticastSocket result4 = this.subject.createMulticastSocket("test", null);
assertSame(socket1, result1);
assertSame(socket2, result2);
assertSame(socket3, result3);
assertSame(socket4, result4);
}
use of java.net.MulticastSocket in project ha-bridge by bwssytems.
the class SystemControl method pingListener.
protected void pingListener() {
try {
byte[] buf = new byte[256];
String testData = "M-SEARCH * HTTP/1.1\nHOST: " + Configuration.UPNP_MULTICAST_ADDRESS + ":" + Configuration.UPNP_DISCOVERY_PORT + "ST: urn:schemas-upnp-org:device:CloudProxy:1\nMAN: \"ssdp:discover\"\nMX: 3";
buf = testData.getBytes();
MulticastSocket socket = new MulticastSocket(Configuration.UPNP_DISCOVERY_PORT);
InetAddress group = InetAddress.getByName(Configuration.UPNP_MULTICAST_ADDRESS);
DatagramPacket packet;
packet = new DatagramPacket(buf, buf.length, group, Configuration.UPNP_DISCOVERY_PORT);
socket.send(packet);
socket.close();
} catch (IOException e) {
log.warn("Error pinging listener. " + e.getMessage());
}
}
use of java.net.MulticastSocket in project dubbo by alibaba.
the class MulticastRegistryTest method testDefaultPort.
@Test
public void testDefaultPort() {
MulticastRegistry multicastRegistry = new MulticastRegistry(URL.valueOf("multicast://224.5.6.7"));
try {
MulticastSocket multicastSocket = multicastRegistry.getMutilcastSocket();
Assert.assertEquals(1234, multicastSocket.getLocalPort());
} finally {
multicastRegistry.destroy();
}
}
use of java.net.MulticastSocket in project jdk8u_jdk by JetBrains.
the class SetGetNetworkInterfaceTest method main.
public static void main(String[] args) throws Exception {
boolean passed = true;
try {
MulticastSocket ms = new MulticastSocket();
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
while (networkInterfaces.hasMoreElements()) {
NetworkInterface netIf = networkInterfaces.nextElement();
if (isNetworkInterfaceTestable(netIf)) {
printNetIfDetails(netIf);
ms.setNetworkInterface(netIf);
NetworkInterface msNetIf = ms.getNetworkInterface();
if (netIf.equals(msNetIf)) {
System.out.println(" OK");
} else {
System.out.println("FAILED!!!");
printNetIfDetails(msNetIf);
passed = false;
}
System.out.println("------------------");
}
}
} catch (IOException e) {
e.printStackTrace();
passed = false;
}
if (!passed) {
throw new RuntimeException("Test Fail");
}
System.out.println("Test passed ");
}
Aggregations