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:cloudfoundry.norouter.Main.java

@Bean
MetronClient metronClient() {/*from www .  j  a v a 2  s  .co  m*/
    return MetronClientBuilder.create("norouter")
            .metronAgent(new InetSocketAddress(metronProperties.getAddress(), metronProperties.getPort()))
            .build();
}

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

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

From source file:ti.modules.titanium.network.NonValidatingSSLSocketFactory.java

@Override
public Socket connectSocket(Socket sock, String host, int port, InetAddress localAddress, int localPort,
        HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
    if (host == null) {
        throw new IllegalArgumentException("Target host may not be null.");
    }/*from   w ww.  j  a v  a 2 s .  c  o m*/
    if (params == null) {
        throw new IllegalArgumentException("Parameters may not be null.");
    }

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

    if ((localAddress != null) || (localPort > 0)) {

        // we need to bind explicitly
        if (localPort < 0)
            localPort = 0; // indicates "any"

        InetSocketAddress isa = new InetSocketAddress(localAddress, localPort);
        sslsock.bind(isa);
    }

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

    InetSocketAddress remoteAddress = new InetSocketAddress(host, port);
    sslsock.connect(remoteAddress, connTimeout);
    sslsock.setSoTimeout(soTimeout);

    return sslsock;
}

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

public Socket createSocket(String host, int port, InetAddress localAddress, int localPort,
        HttpConnectionParams params) throws IOException {
    if (params == null) {
        throw new IllegalArgumentException("Parameters may not be null");
    }//from www.  java 2s. c o  m
    int timeout = params.getConnectionTimeout();
    if (timeout == 0) {
        return createSocket(host, port, localAddress, localPort);
    } else {
        TimedSocket socket = new TimedSocket();
        socket.bind(new InetSocketAddress(localAddress, localPort));
        socket.connect(new InetSocketAddress(host, port), timeout);
        return sslFactory.createSocket(socket, host, port, true);
    }
}

From source file:at.alladin.rmbt.android.util.CheckIpTask.java

@Override
protected JSONArray doInBackground(final Void... params) {
    needsRetry = false;//from   www. ja v  a  2  s .  co m
    serverConn = new ControlServerConnection(activity);

    try {
        Socket s = new Socket();
        InetSocketAddress addr = new InetSocketAddress(
                ConfigHelper.getCachedControlServerNameIpv4(activity.getApplicationContext()),
                ConfigHelper.getControlServerPort(activity.getApplicationContext()));
        s.connect(addr, 5000);

        privateIpv4 = s.getLocalAddress();
        s.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        Socket s = new Socket();
        InetSocketAddress addr = new InetSocketAddress(
                ConfigHelper.getCachedControlServerNameIpv6(activity.getApplicationContext()),
                ConfigHelper.getControlServerPort(activity.getApplicationContext()));
        s.connect(addr, 5000);

        privateIpv6 = s.getLocalAddress();
        s.close();
    } catch (SocketTimeoutException e) {
        e.printStackTrace();
        needsRetry = ConfigHelper.isRetryRequiredOnIpv6SocketTimeout(activity);
    } catch (Exception e) {
        needsRetry = false;
        e.printStackTrace();
    }

    newsList = new JSONArray();

    if (privateIpv4 != null) {
        JSONArray response = serverConn.requestIp(false);
        if (response != null && response.length() >= 1) {
            newsList.put(response.opt(0));
        }
    } else {
        Log.d(DEBUG_TAG, "no private ipv4 found");
    }

    if (privateIpv6 != null) {
        JSONArray response = serverConn.requestIp(true);
        if (response != null && response.length() >= 1) {
            newsList.put(response.opt(0));
        }
    } else {
        Log.d(DEBUG_TAG, "no private ipv6 found");
    }

    return newsList;
}

From source file:com.log4ic.compressor.utils.MemcachedUtils.java

private static InetSocketAddress biludAddr(Node node) {
    Node hostNode = node.selectSingleNode("host");
    Node portNode = node.selectSingleNode("port");
    if (hostNode != null && StringUtils.isNotBlank(hostNode.getText()) && portNode != null
            && StringUtils.isNotBlank(portNode.getText())) {
        return new InetSocketAddress(hostNode.getText(), Integer.parseInt(portNode.getText()));
    }/*from  ww  w . j a v a  2s.c  om*/
    return null;
}

From source file:code.google.nfs.rpc.netty.client.NettyClientFactory.java

protected Client createClient(String targetIP, int targetPort, int connectTimeout, String key)
        throws Exception {
    ClientBootstrap bootstrap = new ClientBootstrap(nioClient);
    bootstrap.setOption("tcpNoDelay", Boolean.parseBoolean(System.getProperty("nfs.rpc.tcp.nodelay", "true")));
    bootstrap.setOption("reuseAddress",
            Boolean.parseBoolean(System.getProperty("nfs.rpc.tcp.reuseaddress", "true")));
    if (connectTimeout < 1000) {
        bootstrap.setOption("connectTimeoutMillis", 1000);
    } else {//from   w  ww . j a  v a2s  . c o m
        bootstrap.setOption("connectTimeoutMillis", connectTimeout);
    }
    NettyClientHandler handler = new NettyClientHandler(this, key);
    bootstrap.setPipelineFactory(new NettyClientPipelineFactory(handler));
    ChannelFuture future = bootstrap.connect(new InetSocketAddress(targetIP, targetPort));
    future.awaitUninterruptibly(connectTimeout);
    if (!future.isDone()) {
        LOGGER.error("Create connection to " + targetIP + ":" + targetPort + " timeout!");
        throw new Exception("Create connection to " + targetIP + ":" + targetPort + " timeout!");
    }
    if (future.isCancelled()) {
        LOGGER.error("Create connection to " + targetIP + ":" + targetPort + " cancelled by user!");
        throw new Exception("Create connection to " + targetIP + ":" + targetPort + " cancelled by user!");
    }
    if (!future.isSuccess()) {
        LOGGER.error("Create connection to " + targetIP + ":" + targetPort + " error", future.getCause());
        throw new Exception("Create connection to " + targetIP + ":" + targetPort + " error",
                future.getCause());
    }
    NettyClient client = new NettyClient(future, key, connectTimeout);
    handler.setClient(client);
    return client;
}

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

/**
 * @param nc//from w  ww  .ja v a  2 s .com
 */
public SimpleReconfiguratorNodeConfig(ReconfigurableNodeConfig<NodeIDType> nc) {
    this.nodeConfig = nc;
    for (NodeIDType node : nc.getReconfigurators()) {
        this.rcMap.put(node, new InetSocketAddress(nc.getNodeAddress(node), nc.getNodePort(node)));
        this.rcBindMap.put(node, nc.getBindAddress(node));
    }
}

From source file:dk.dma.ais.bus.provider.TcpClientProvider.java

@Override
public void run() {
    setNotConnected();/*from  ww w  .j a  v a2 s  .  co  m*/
    while (true) {
        socket = new Socket();

        // Get next host and port
        selectHost();
        String host = hostnames.get(currentHost);
        int port = ports.get(currentHost);

        // Connect
        try {
            InetSocketAddress address = new InetSocketAddress(host, port);
            LOG.info("Connecting to " + host + ":" + port + " ...");
            socket.connect(address);
            socket.setKeepAlive(true);
            if (timeout > 0) {
                socket.setSoTimeout(timeout * 1000);
            }

            setConnected();

            // Start client
            readClient = new TcpReadClient(this, this, socket, clientConf);
            readClient.start();
            // Wait for client to loose connection
            readClient.join();
            readClient = null;
        } catch (IOException e) {
            LOG.info(getName() + ": connection error: " + e.getMessage());
        } catch (InterruptedException e) {
            readClient.cancel();
            break;
        }

        setNotConnected();

        try {
            LOG.info("Waiting to reconnect");
            Thread.sleep(reconnectInterval * 1000);
        } catch (InterruptedException e) {
            break;
        }

    }

    setStopped();
}

From source file:com.parallax.server.blocklyprop.monitoring.Monitor.java

private void init() {
    if (consoleEnabled) {
        ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics)
                .convertDurationsTo(TimeUnit.MILLISECONDS).build();
        reporter.start(consoleReportingInterval, TimeUnit.SECONDS);
    }/* ww w  . j  a va  2s  .c  o m*/

    if (graphiteEnabled) {
        final PickledGraphite pickledGraphite = new PickledGraphite(
                new InetSocketAddress(graphiteServerAddress, graphiteServerPort));
        final GraphiteReporter graphiteReporter = GraphiteReporter.forRegistry(metrics)
                .prefixedWith(graphitePrefix).convertDurationsTo(TimeUnit.MILLISECONDS).filter(MetricFilter.ALL)
                .build(pickledGraphite);
        graphiteReporter.start(graphiteReportingInterval, TimeUnit.SECONDS);
    }

    InstrumentedAppender appender = new InstrumentedAppender(metrics);
    appender.activateOptions();

    LogManager.getRootLogger().addAppender(appender);

    MemoryUsageGaugeSet memoryUsageGaugeSet = new MemoryUsageGaugeSet();
    metrics.registerAll(memoryUsageGaugeSet);

    GarbageCollectorMetricSet garbageCollectorMetricSet = new GarbageCollectorMetricSet();
    metrics.registerAll(garbageCollectorMetricSet);
}