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.nebkat.junglist.bot.http.EasySSLSocketFactory.java

public Socket connectSocket(Socket sock, InetSocketAddress remoteAddress, InetSocketAddress localAddress,
        HttpParams params) throws IOException {
    int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
    int soTimeout = HttpConnectionParams.getSoTimeout(params);
    int localPort = localAddress != null ? localAddress.getPort() : -1;

    SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket());

    if (localAddress != null) {
        // we need to bind explicitly
        if (localPort < 0) {
            localPort = 0; // indicates "any"
        }//  w w  w .  ja v a  2  s.com
        InetSocketAddress isa = new InetSocketAddress(localAddress.getAddress(), localPort);
        sslsock.bind(isa);
    }

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

}

From source file:ch.epfl.eagle.daemon.scheduler.SchedulerThrift.java

/**
 * Initialize this thrift service.// w  w w  .j a va2  s  .co m
 *
 * This spawns a multi-threaded thrift server and listens for Eagle
 * scheduler requests.
 */
public void initialize(Configuration conf) throws IOException {
    SchedulerService.Processor<SchedulerService.Iface> processor = new SchedulerService.Processor<SchedulerService.Iface>(
            this);
    int port = conf.getInt(EagleConf.SCHEDULER_THRIFT_PORT, DEFAULT_SCHEDULER_THRIFT_PORT);
    int threads = conf.getInt(EagleConf.SCHEDULER_THRIFT_THREADS, DEFAULT_SCHEDULER_THRIFT_THREADS);
    String hostname = Network.getHostName(conf);
    InetSocketAddress addr = new InetSocketAddress(hostname, port);
    scheduler.initialize(conf, addr);
    TServers.launchThreadedThriftServer(port, threads, processor);
    int getTaskPort = conf.getInt(EagleConf.GET_TASK_PORT, DEFAULT_GET_TASK_PORT);
    GetTaskService.Processor<GetTaskService.Iface> getTaskprocessor = new GetTaskService.Processor<GetTaskService.Iface>(
            this);
    TServers.launchSingleThreadThriftServer(getTaskPort, getTaskprocessor);
}

From source file:com.glaf.j2cache.xmemcache.XMemCache.java

protected void buildClient() {
    List<String> list = StringTools.split(servers, ",");
    List<InetSocketAddress> addressList = new ArrayList<InetSocketAddress>();
    for (String server : list) {
        String host = server.substring(0, server.indexOf(":"));
        int port = Integer.parseInt(server.substring(server.indexOf(":") + 1, server.length()));
        InetSocketAddress addr = new InetSocketAddress(host, port);
        addressList.add(addr);//w  w  w . j  ava  2 s.  c o  m
        logger.info("add server-> " + host + ":" + port);
    }
    XMemcachedClientBuilder builder = new XMemcachedClientBuilder(addressList);
    // builder.setConnectionPoolSize(2);
    builder.setTranscoder(new SerializingTranscoder());
    builder.setSessionLocator(new KetamaMemcachedSessionLocator());
    builder.setConnectTimeout(5000);
    builder.setCommandFactory(new BinaryCommandFactory());
    try {
        memcachedClient = builder.build();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:com.comcast.cdn.traffic_control.traffic_monitor.util.Fetcher.java

public static String fetchContent(final String stateUrl, final String ipStr, final int port, final int timeout)
        throws IOException {
    final URLConnection conn = new URL(stateUrl)
            .openConnection(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(ipStr, port)));
    if (timeout != 0) {
        conn.setConnectTimeout(timeout);
        conn.setReadTimeout(timeout);// w ww.j av a  2 s  .  c  om
    }
    conn.connect();

    return IOUtils.toString(new InputStreamReader(conn.getInputStream(), UTF8_STR));
}

From source file:edu.berkeley.sparrow.daemon.scheduler.SchedulerThrift.java

/**
 * Initialize this thrift service./*from w ww .j  ava2 s.  com*/
 *
 * This spawns a multi-threaded thrift server and listens for Sparrow
 * scheduler requests.
 */
public void initialize(Configuration conf) throws IOException {
    SchedulerService.Processor<SchedulerService.Iface> processor = new SchedulerService.Processor<SchedulerService.Iface>(
            this);
    int port = conf.getInt(SparrowConf.SCHEDULER_THRIFT_PORT, DEFAULT_SCHEDULER_THRIFT_PORT);
    int threads = conf.getInt(SparrowConf.SCHEDULER_THRIFT_THREADS, DEFAULT_SCHEDULER_THRIFT_THREADS);
    String hostname = Network.getHostName(conf);
    InetSocketAddress addr = new InetSocketAddress(hostname, port);
    scheduler.initialize(conf, addr);
    TServers.launchThreadedThriftServer(port, threads, processor);
    int getTaskPort = conf.getInt(SparrowConf.GET_TASK_PORT, DEFAULT_GET_TASK_PORT);
    GetTaskService.Processor<GetTaskService.Iface> getTaskprocessor = new GetTaskService.Processor<GetTaskService.Iface>(
            this);
    TServers.launchSingleThreadThriftServer(getTaskPort, getTaskprocessor);
}

From source file:com.navercorp.pinpoint.collector.receiver.thrift.udp.UDPReceiverTest.java

@Test
public void startStop() {
    UDPReceiver receiver = null;//from  w w  w . jav  a2 s  .  com

    InetSocketAddress bindAddress = new InetSocketAddress(ADDRESS, PORT);

    Executor executor = MoreExecutors.directExecutor();
    PacketHandlerFactory packetHandlerFactory = mock(PacketHandlerFactory.class);
    when(packetHandlerFactory.createPacketHandler()).thenReturn(loggingPacketHandler);
    try {
        ObjectPoolFactory<DatagramPacket> packetFactory = new DatagramPacketFactory();
        ObjectPool<DatagramPacket> pool = new DefaultObjectPool<>(packetFactory, 10);
        receiver = new UDPReceiver("test", packetHandlerFactory, executor, 8, bindAddress, pool);
    } catch (Exception e) {
        logger.debug(e.getMessage(), e);
        Assert.fail(e.getMessage());
    } finally {
        if (receiver != null) {
            receiver.shutdown();
        }
    }
}

From source file:code.google.nfs.rpc.mina2.client.MinaClientFactory.java

protected Client createClient(String targetIP, int targetPort, int connectTimeout, String key)
        throws Exception {
    if (isDebugEnabled) {
        LOGGER.debug("create connection to :" + targetIP + ":" + targetPort + ",timeout is:" + connectTimeout
                + ",key is:" + key);
    }//ww  w  .  j  a  v a  2 s  .  c  om
    if (connectTimeout > 1000) {
        ioConnector.setConnectTimeoutMillis((int) connectTimeout);
    } else {
        ioConnector.setConnectTimeoutMillis(1000);
    }
    SocketAddress targetAddress = new InetSocketAddress(targetIP, targetPort);
    MinaClientProcessor processor = new MinaClientProcessor(this, key);
    ioConnector.setHandler(processor);
    ConnectFuture connectFuture = ioConnector.connect(targetAddress);
    // wait for connection established
    connectFuture.awaitUninterruptibly();

    IoSession ioSession = connectFuture.getSession();
    if ((ioSession == null) || (!ioSession.isConnected())) {
        String targetUrl = targetIP + ":" + targetPort;
        LOGGER.error("create connection error,targetaddress is " + targetUrl);
        throw new Exception("create connection error,targetaddress is " + targetUrl);
    }
    if (isDebugEnabled) {
        LOGGER.debug("create connection to :" + targetIP + ":" + targetPort + ",timeout is:" + connectTimeout
                + ",key is:" + key + " successed");
    }
    MinaClient client = new MinaClient(ioSession, key, connectTimeout);
    processor.setClient(client);
    return client;
}

From source file:com.lolay.android.security.OpenSSLSocketFactory.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)) {
        if (localPort < 0) {
            localPort = 0;//from www.  j a  v  a  2  s  .  com
        }
        InetSocketAddress isa = new InetSocketAddress(localAddress, localPort);
        sslsock.bind(isa);
    }

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

From source file:pydio.sdk.java.utils.AjxpSSLSocketFactory.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 sslsock = (SSLSocket) ((sock != null) ? sock : createSocket());

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

    sslsock.connect(remoteAddress, connTimeout);
    sslsock.setSoTimeout(soTimeout);
    //sslsock.setEnabledProtocols(new String[]{"TLSv1", "TLSv1.1", "TLSv1.2"});
    return sslsock;
}

From source file:info.ajaxplorer.client.http.AjxpSSLSocketFactory.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 sslsock = (SSLSocket) ((sock != null) ? sock : createSocket());

    if ((localAddress != null) || (localPort > 0)) {
        // we need to bind explicitly
        if (localPort < 0) {
            localPort = 0; // indicates "any"
        }//from w ww .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;
}