Code example for InetSocketAddress

Methods: isUnresolved

1
        InetSocketAddress isa3 = new InetSocketAddress("0.0.0.0", 8080);
        assertFalse(isa1.hashCode() == isa3.hashCode());
    } 
 
    public void test_isUnresolved() { 
        InetSocketAddress isa1 = new InetSocketAddress("localhost", 80);
        assertFalse(isa1.isUnresolved());
 
        InetSocketAddress sockAddr = new InetSocketAddress("unknown.host", 1000);
        assertTrue(sockAddr.isUnresolved());
    } 
 
    public void test_getHostString() throws Exception { 
        // When we have a hostname, we'll get it back because that doesn't cost a DNS lookup... 
        InetSocketAddress hasHostname = InetSocketAddress.createUnresolved("some host", 1234);
        assertEquals("some host", hasHostname.getHostString());
        assertEquals("some host", hasHostname.getHostName());
        // When we don't have a hostname, whether or not we do the reverse lookup is the difference 
        // between getHostString and getHostName... 
        InetAddress address = InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 });
        InetSocketAddress noHostname = new InetSocketAddress(address, 1234);