Code example for NetworkInterface

Methods: getInetAddresses

0
 
    private void test_joinGroupLjava_net_InetAddress(InetAddress group) throws Exception {
        int[] ports = Support_PortManager.getNextPortsForUDP(2);
        int groupPort = ports[0];
 
        MulticastServer server = new MulticastServer(group, groupPort);
        server.start();
        Thread.sleep(1000);
        String msg = "Hello World";
        MulticastSocket mss = new MulticastSocket(ports[1]);
        DatagramPacket sdp = new DatagramPacket(msg.getBytes(), msg.length(), group, groupPort);
        mss.send(sdp, (byte) 10);
        Thread.sleep(1000);
        String receivedMessage = new String(server.rdp.getData(), 0, server.rdp.getLength());
        assertEquals("Group member did not recv data", msg, receivedMessage);
        mss.close();
        server.stopServer();
    } 
 
    public void test_joinGroup_null_null() throws Exception { 
        MulticastSocket mss = new MulticastSocket(0);
        try { 
            mss.joinGroup(null, null);
            fail();
        } catch (IllegalArgumentException expected) {
        } 
        mss.close();
    } 
 
    public void test_joinGroup_non_multicast_address_IPv4() throws Exception { 
        MulticastSocket mss = new MulticastSocket(0);
        try { 
            mss.joinGroup(new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 0), null);
            fail();
        } catch (IOException expected) {
        } 
        mss.close();