Example usage for java.net InetSocketAddress InetSocketAddress

List of usage examples for java.net InetSocketAddress InetSocketAddress

Introduction

In this page you can find the example usage for java.net InetSocketAddress InetSocketAddress.

Prototype

private InetSocketAddress(int port, String hostname) 

Source Link

Usage

From source file:com.twitter.distributedlog.client.proxy.TestProxyClientManager.java

private static SocketAddress createSocketAddress(int port) {
    return new InetSocketAddress("127.0.0.1", port);
}

From source file:com.couchbase.client.ViewConnectionTest.java

@Test
public void shouldInitializeWithHosts() throws Exception {
    List<InetSocketAddress> initialNodes = Arrays.asList(new InetSocketAddress("10.0.0.1", PORT),
            new InetSocketAddress("10.0.0.2", PORT));

    ViewConnection conn = new ViewConnection(factoryMock, initialNodes, DEFAULT_USER, DEFAULT_PASS);

    List<HttpHost> connected = conn.getConnectedHosts();
    assertEquals(2, connected.size());/*w w  w . j a  va 2 s .  co  m*/
    assertEquals("10.0.0.1:" + PORT, connected.get(0).toHostString());
    assertEquals("10.0.0.2:" + PORT, connected.get(1).toHostString());
}

From source file:io.github.bonigarcia.wdm.WdmHttpClient.java

Proxy createProxy(String proxyUrl) {
    URL url = determineProxyUrl(proxyUrl);
    if (url == null) {
        return null;
    }/*from w  w  w  .  jav a 2 s .c  om*/
    String proxyHost = url.getHost();
    int proxyPort = url.getPort() == -1 ? 80 : url.getPort();
    return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));
}

From source file:edu.umass.cs.reconfiguration.reconfigurationutils.ConsistentNodeConfig.java

/**
 * @param id//from ww w .j  a v  a 2 s  .  c o m
 * @return Socket address corresponding to node {@code id}.
 */
public InetSocketAddress getNodeSocketAddress(NodeIDType id) {
    InetAddress ip = this.getNodeAddress(id);
    return (ip != null ? new InetSocketAddress(ip, this.getNodePort(id)) : null);
}

From source file:com.sun.faban.driver.transport.hc3.AboveTimedSSLSocketFactory.java

public Socket createSocket(String host, int port) throws IOException {
    Socket socket = new TimedSocketWrapper(sslFactory.createSocket());
    InetSocketAddress endpoint = new InetSocketAddress(host, port);
    socket.connect(endpoint);//from w  ww.  j a  va2 s  .  c om
    return socket;
}

From source file:uk.co.flax.biosolr.ontology.documents.storage.elasticsearch.ESStorageEngine.java

@SuppressWarnings("resource")
@Override/*  w  w  w . j av  a  2  s .c  om*/
public void initialise() throws StorageEngineException {
    if (config.isUseNodeClient()) {
        Node node = new NodeBuilder().client(true).clusterName(config.getClusterName()).build();
        client = node.client();
    } else {
        TransportAddress[] serverAddresses = config.getServers().stream().map(HostAndPort::fromString)
                .map(hp -> new InetSocketTransportAddress(
                        new InetSocketAddress(hp.getHostText(), hp.getPortOrDefault(DEFAULT_PORT))))
                .toArray(size -> new TransportAddress[size]);
        client = TransportClient.builder().build().addTransportAddresses(serverAddresses);
    }
}

From source file:com.spotify.ffwd.protocol.ProtocolFactory.java

private InetSocketAddress parseSocketAddress(String host, Integer port, int defaultPort, String defaultHost) {
    if (host == null)
        host = defaultHost;/*from   w  w  w .  ja  v  a2 s. co  m*/

    if (port == null)
        port = defaultPort;

    return new InetSocketAddress(host, port);
}

From source file:com.suning.mobile.ebuy.lottery.network.util.EasySSLSocketFactory.java

/**
 * @see org.apache.http.conn.scheme.SocketFactory#connectSocket(java.net.Socket,
 *      java.lang.String, int, java.net.InetAddress, int,
 *      org.apache.http.params.HttpParams)
 *///  ww w.j ava  2  s  .  c o  m
@Override
public Socket connectSocket(Socket sock, String host, int port, InetAddress localAddress, int localPort,
        HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
    int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
    int soTimeout = HttpConnectionParams.getSoTimeout(params);
    int tempLocalPort = localPort;

    InetSocketAddress remoteAddress = new InetSocketAddress(host, port);
    SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket());

    if ((localAddress != null) || (tempLocalPort > 0)) {
        // we need to bind explicitly
        if (tempLocalPort < 0) {
            tempLocalPort = 0; // indicates "any"
        }
        InetSocketAddress isa = new InetSocketAddress(localAddress, tempLocalPort);
        sslsock.bind(isa);
    }

    sslsock.connect(remoteAddress, connTimeout);
    sslsock.setSoTimeout(soTimeout);
    return sslsock;

}