Example usage for io.netty.util NetUtil LOCALHOST4

List of usage examples for io.netty.util NetUtil LOCALHOST4

Introduction

In this page you can find the example usage for io.netty.util NetUtil LOCALHOST4.

Prototype

Inet4Address LOCALHOST4

To view the source code for io.netty.util NetUtil LOCALHOST4.

Click Source Link

Document

The Inet4Address that represents the IPv4 loopback address '127.0.0.1'

Usage

From source file:com.andrewkroh.cisco.rtp.NettyRtpSessionTest.java

License:Apache License

@Test
public void sendData_toUnicastDestination_packetIsReceived() throws Exception {
    session = new NettyRtpSession(new InetSocketAddress(TestUtils.getFreePort()));
    session.addDestination(//from   ww  w.j  a v  a 2 s . com
            new Destination(NetUtil.LOCALHOST4.getHostAddress(), clientChannel.localAddress().getPort()));
    session.sendData(rtpPacket);
    assertThatPayloadDataMatches(clientHandler.getOnlyReceivedPacket());
}

From source file:com.linecorp.armeria.server.SniServerTest.java

License:Apache License

@Override
protected void configureServer(ServerBuilder sb) throws Exception {
    dnsResolver = new InMemoryDnsResolver();
    dnsResolver.add("a.com", NetUtil.LOCALHOST4);
    dnsResolver.add("b.com", NetUtil.LOCALHOST4);
    dnsResolver.add("c.com", NetUtil.LOCALHOST4);
    dnsResolver.add("mismatch.com", NetUtil.LOCALHOST4);
    dnsResolver.add("127.0.0.1", NetUtil.LOCALHOST4);

    sscA = new SelfSignedCertificate("a.com");
    sscB = new SelfSignedCertificate("b.com");
    sscC = new SelfSignedCertificate("c.com");

    final VirtualHostBuilder a = new VirtualHostBuilder("a.com");
    final VirtualHostBuilder b = new VirtualHostBuilder("b.com");
    final VirtualHostBuilder c = new VirtualHostBuilder("c.com");

    a.serviceAt("/", new AbstractHttpService() {
        @Override//from   w w  w .  jav a  2  s .  c  o m
        protected void doGet(ServiceRequestContext ctx, HttpRequest req, HttpResponseWriter res) {
            res.respond(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, "a.com");
        }
    });

    b.serviceAt("/", new AbstractHttpService() {
        @Override
        protected void doGet(ServiceRequestContext ctx, HttpRequest req, HttpResponseWriter res) {
            res.respond(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, "b.com");
        }
    });

    c.serviceAt("/", new AbstractHttpService() {
        @Override
        protected void doGet(ServiceRequestContext ctx, HttpRequest req, HttpResponseWriter res) {
            res.respond(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, "c.com");
        }
    });

    a.sslContext(SessionProtocol.HTTPS, sscA.certificate(), sscA.privateKey());
    b.sslContext(SessionProtocol.HTTPS, sscB.certificate(), sscB.privateKey());
    c.sslContext(SessionProtocol.HTTPS, sscC.certificate(), sscC.privateKey());

    sb.virtualHost(a.build());
    sb.virtualHost(b.build());
    sb.defaultVirtualHost(c.build());

    sb.port(0, SessionProtocol.HTTPS);
}

From source file:io.vertx.core.dns.impl.fix.DnsQueryContextManager.java

License:Apache License

private IntObjectMap<DnsQueryContext> getOrCreateContextMap(InetSocketAddress nameServerAddr) {
    synchronized (map) {
        final IntObjectMap<DnsQueryContext> contexts = map.get(nameServerAddr);
        if (contexts != null) {
            return contexts;
        }// w  w w .  j av a 2s. c  o m

        final IntObjectMap<DnsQueryContext> newContexts = new IntObjectHashMap<DnsQueryContext>();
        final InetAddress a = nameServerAddr.getAddress();
        final int port = nameServerAddr.getPort();
        map.put(nameServerAddr, newContexts);

        if (a instanceof Inet4Address) {
            // Also add the mapping for the IPv4-compatible IPv6 address.
            final Inet4Address a4 = (Inet4Address) a;
            if (a4.isLoopbackAddress()) {
                map.put(new InetSocketAddress(NetUtil.LOCALHOST6, port), newContexts);
            } else {
                map.put(new InetSocketAddress(toCompatAddress(a4), port), newContexts);
            }
        } else if (a instanceof Inet6Address) {
            // Also add the mapping for the IPv4 address if this IPv6 address is compatible.
            final Inet6Address a6 = (Inet6Address) a;
            if (a6.isLoopbackAddress()) {
                map.put(new InetSocketAddress(NetUtil.LOCALHOST4, port), newContexts);
            } else if (a6.isIPv4CompatibleAddress()) {
                map.put(new InetSocketAddress(toIPv4Address(a6), port), newContexts);
            }
        }

        return newContexts;
    }
}