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.chiralBehaviors.slp.hive.hardtack.configuration.AggregatorConfiguration.java

@Override
public Engine construct() throws IOException {
    NetworkInterface intf = getNetworkInterface();
    DatagramSocket socket;//from   w w  w. j  av  a 2 s . co m
    InetSocketAddress address;
    if (endpoint.getAddress().isAnyLocalAddress()) {
        address = new InetSocketAddress(Utils.getAddress(intf, ipv4), endpoint.getPort());
    } else {
        address = endpoint;
    }
    try {
        socket = new DatagramSocket(address);
    } catch (BindException e) {
        BindException bindException = new BindException(String.format("Cannot bind to %s", address));
        bindException.initCause(e);
        throw bindException;
    }
    return new AggregatorEngine(socket, getMac(), Executors.newSingleThreadScheduledExecutor(), getFdFactory());
}

From source file:pt.hive.cameo.ssl.SSLSocketFactory.java

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);

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

    if ((localAddress != null) || (localPort > 0)) {
        if (localPort < 0) {
            localPort = 0;//from   w  ww .  j  a  v a  2 s . c o m
        }
        InetSocketAddress isa = new InetSocketAddress(localAddress, localPort);
        sslSocket.bind(isa);
    }

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

}

From source file:com.micro.http.ssl.EasySSLProtocolSocketFactory.java

@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);

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

    if ((localAddress != null) || (localPort > 0)) {
        // we need to bind explicitly
        if (localPort < 0) {
            localPort = 0; // indicates "any"
        }// ww w.ja va  2 s.c o m
        InetSocketAddress isa = new InetSocketAddress(localAddress, localPort);
        sslsock.bind(isa);
    }

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

}

From source file:com.vmware.photon.controller.cloudstore.xenon.entity.IpLeaseServiceTest.java

@BeforeSuite
public void beforeSuite() throws Throwable {
    host = BasicServiceHost.create();//from  ww w . j av a 2s . c  om
    ServiceHostUtils.startFactoryServices(host, CloudStoreServiceGroup.FACTORY_SERVICES_MAP);

    StaticServerSet serverSet = new StaticServerSet(
            new InetSocketAddress(host.getPreferredAddress(), host.getPort()));
    xenonClient = new XenonRestClient(serverSet, Executors.newFixedThreadPool(128),
            Executors.newScheduledThreadPool(1), host);
    xenonClient.start();
}

From source file:com.vmware.photon.controller.cloudstore.xenon.entity.DhcpSubnetServiceTest.java

@BeforeSuite
public void beforeSuite() throws Throwable {
    host = BasicServiceHost.create();/*from   w  ww.j av  a2 s . co m*/
    ServiceHostUtils.startFactoryServices(host, CloudStoreServiceGroup.FACTORY_SERVICES_MAP);

    StaticServerSet serverSet = new StaticServerSet(
            new InetSocketAddress(host.getPreferredAddress(), host.getPort()));
    xenonClient = new XenonRestClient(serverSet, Executors.newFixedThreadPool(128),
            Executors.newScheduledThreadPool(1));
    xenonClient.start();
}

From source file:com.hellblazer.jackal.configuration.basic.LocalGossipConfiguration.java

@Bean(name = "gossipEndpoint")
public InetSocketAddress gossipEndpoint() {
    return new InetSocketAddress("127.0.0.1", 0);
}

From source file:com.talis.platform.sequencing.zookeeper.ZkTestHelper.java

public NIOServerCnxn.Factory createNewServerInstance(File dataDir, String hostPort, int maxCnxns)
        throws IOException, InterruptedException {

    try {//from   www .  j ava  2 s .  co m

        ZooKeeperServer zks = new ZooKeeperServer(dataDir, dataDir, 3000);

        final int port = getPort(hostPort);
        final String host = getHost(hostPort);
        InetSocketAddress address = new InetSocketAddress(host, port);
        NIOServerCnxn.Factory factory = new NIOServerCnxn.Factory(address);
        factory.startup(zks);

        assertTrue("waiting for server up", waitForServerUp(host + ":" + port, CONNECTION_TIMEOUT));

        return factory;
    } catch (IOException e) {
        e.printStackTrace();
        throw e;
    }
}

From source file:piazza.commons.elasticsearch.NativeElasticsearchTemplateConfiguration.java

@Bean
public Client client() throws UnknownHostException {
    //      TransportClient client = TransportClient.builder().build()
    //              .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostname), port));

    Settings settings = Settings.settingsBuilder().put("cluster.name", clustername).build();

    TransportClient transportClient = TransportClient.builder().settings(settings).build();

    //      transportClient.addTransportAddress(new InetSocketTransportAddress(
    //                                 InetAddress.getByName(cfhostname), port));
    transportClient/* www.j a  v a  2 s .  c  o m*/
            .addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress(cfhostname, port)));

    return transportClient;
}

From source file:cn.hi321.browser.weave.client.WeaveSSLSocketFactory.java

/**
 * @see SocketFactory#connectSocket(Socket, String, int, InetAddress, int, HttpParams)
 *///from w  w  w . j a v a2 s  .c  o m
public Socket connectSocket(Socket sock, String host, int port, InetAddress localAddress, int localPort,
        HttpParams params) throws IOException {

    int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
    int soTimeout = HttpConnectionParams.getSoTimeout(params);

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

    if ((localAddress != null) || (localPort > 0)) {
        if (localPort < 0) {
            localPort = 0;
        }
        InetSocketAddress isa = new InetSocketAddress(localAddress, localPort);
        sslsock.bind(isa);
    }

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

}

From source file:com.jivesoftware.os.jive.utils.http.client.CustomSecureProtocolSocketFactoryTest.java

@Test
public void testCreateSocketLocalWithTimeout() throws Exception {
    HttpConnectionParams params = mock(HttpConnectionParams.class);
    Socket socket = mock(Socket.class);

    when(params.getConnectionTimeout()).thenReturn(788);
    when(params.getSoTimeout()).thenReturn(789);
    when(sslSocketFactory.createSocket()).thenReturn(socket);

    customSecureProtocolSocketFactory.createSocket("host", 444, InetAddress.getLocalHost(), 8765, params);

    verify(sslSocketFactory).createSocket();
    verify(socket).setSoTimeout(789);//from  w w  w.j  a  v  a2s . c  om
    verify(socket).connect(new InetSocketAddress("host", 444), 788);
}