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:org.jclouds.http.httpnio.pool.NioHttpCommandConnectionPoolTest.java

public void testConstructorUnspecifiedPort() throws Exception {
    NioHttpCommandConnectionPool pool = new NioHttpCommandConnectionPool(null, null, null, null,
            createNiceMock(AsyncNHttpClientHandler.class), null, createNiceMock(HttpParams.class),
            URI.create("http://localhost"));
    assertEquals(pool.getTarget(), new InetSocketAddress("localhost", 80));
}

From source file:hd3gtv.as5kpc.Serverchannel.java

private Socket connect() throws IOException {
    Socket socket = new Socket();
    socket.setKeepAlive(false);//from  ww w.  j a v  a  2  s. c om
    socket.connect(new InetSocketAddress(server, port), 4000);
    return socket;
}

From source file:com.googlecode.jsendnsca.NagiosPassiveCheckSender.java

private Socket connectedToNagios() throws IOException {
    Socket socket = new Socket();
    socket.connect(new InetSocketAddress(nagiosSettings.getNagiosHost(), nagiosSettings.getPort()),
            nagiosSettings.getConnectTimeout());
    socket.setSoTimeout(nagiosSettings.getTimeout());
    return socket;
}

From source file:info.guardianproject.net.SocksSocketFactory.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.");
    }// w w  w. ja v  a 2 s  . com
    if (params == null) {
        throw new IllegalArgumentException("Parameters may not be null.");
    }

    if (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);
        sock.bind(isa);
    }

    return new SocksSocket(sProxy, host, port);

}

From source file:org.elasticsearch.client.RestClientMultipleHostsIntegTests.java

private static HttpServer createHttpServer() throws Exception {
    HttpServer httpServer = MockHttpServer
            .createHttp(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), 0);
    httpServer.start();//from  w w w. j  a  v a  2 s.c  o  m
    //returns a different status code depending on the path
    for (int statusCode : getAllStatusCodes()) {
        httpServer.createContext(pathPrefix + "/" + statusCode, new ResponseHandler(statusCode));
    }
    return httpServer;
}

From source file:com.ibasco.agql.examples.McRconQueryEx.java

public void testRcon() throws InterruptedException {
    String address = promptInput("Please enter the minecraft server address", true, "", "mcRconIp");
    int port = Integer.valueOf(promptInput("Please enter the server port", false, "25575", "mcRconPort"));

    boolean authenticated = false;

    InetSocketAddress serverAddress = new InetSocketAddress(address, port);

    while (!authenticated) {
        String password = promptInput("Please enter the rcon password", true, "", "msRconPass");
        log.info("Connecting to server {}:{}, with password = {}", address, port,
                StringUtils.replaceAll(password, ".", "*"));
        SourceRconAuthStatus authStatus = mcRconClient.authenticate(serverAddress, password).join();
        if (!authStatus.isAuthenticated()) {
            log.error("ERROR: Could not authenticate from server (Reason: {})", authStatus.getReason());
        } else/*w w  w  .  j  a v a  2 s. co  m*/
            authenticated = true;
    }

    log.info("Successfully authenticated from server : {}", address);
    while (true) {
        String command = promptInput("\nEnter rcon command: ", true);
        try {
            mcRconClient.execute(serverAddress, command).whenComplete(this::handleResponse).join();
        } catch (RconNotYetAuthException e) {
            throw new RuntimeException(e);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
        }
    }
}

From source file:com.chiralBehaviors.slp.hive.hardtack.configuration.PushConfiguration.java

@Override
public Engine construct() throws IOException {
    NetworkInterface intf = getNetworkInterface();
    InetAddress address = Utils.getAddress(intf, ipv4);
    DatagramSocket p2pSocket = new DatagramSocket(new InetSocketAddress(address, Utils.allocatePort(address)));
    int i = 0;//from   www.  jav  a 2s . c o m
    for (InetSocketAddress aggregator : aggregators) {
        log.info(String.format("Adding aggregator: %s", aggregator));
        if (aggregator.getAddress().isAnyLocalAddress()) {
            aggregators.set(i++, new InetSocketAddress(address, aggregator.getPort()));
        }
    }
    return new PushEngine(p2pSocket, getMac(), Generators.timeBasedGenerator(), aggregators, heartbeatPeriod,
            heartbeatUnit, Executors.newSingleThreadScheduledExecutor());

}

From source file:com.predic8.membrane.core.transport.http.Connection.java

public static Connection open(InetAddress host, int port, String localHost, SSLProvider sslProvider,
        ConnectionManager mgr, int connectTimeout) throws UnknownHostException, IOException {
    Connection con = new Connection(mgr);

    if (sslProvider != null) {
        if (isNullOrEmpty(localHost))
            con.socket = sslProvider.createSocket(host, port, connectTimeout);
        else//from   w  w  w  .j ava  2s .c o m
            con.socket = sslProvider.createSocket(host, port, InetAddress.getByName(localHost), 0,
                    connectTimeout);
    } else {
        if (isNullOrEmpty(localHost)) {
            con.socket = new Socket();
        } else {
            con.socket = new Socket();
            con.socket.bind(new InetSocketAddress(InetAddress.getByName(localHost), 0));
        }
        con.socket.connect(new InetSocketAddress(host, port), connectTimeout);
    }

    log.debug("Opened connection on localPort: " + con.socket.getLocalPort());
    //Creating output stream before input stream is suggested.
    con.out = new BufferedOutputStream(con.socket.getOutputStream(), 2048);
    con.in = new BufferedInputStream(con.socket.getInputStream(), 2048);

    return con;
}

From source file:code.google.nfs.rpc.mina.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);
    }//from   ww  w .  j a  va 2s.c o  m
    SocketConnectorConfig cfg = new SocketConnectorConfig();
    cfg.setThreadModel(ThreadModel.MANUAL);
    if (connectTimeout > 1000) {
        cfg.setConnectTimeout((int) connectTimeout / 1000);
    } else {
        cfg.setConnectTimeout(1);
    }
    cfg.getSessionConfig()
            .setTcpNoDelay(Boolean.parseBoolean(System.getProperty("nfs.rpc.tcp.nodelay", "true")));
    cfg.getFilterChain().addLast("objectserialize", new MinaProtocolCodecFilter());
    SocketAddress targetAddress = new InetSocketAddress(targetIP, targetPort);
    MinaClientProcessor processor = new MinaClientProcessor(this, key);
    ConnectFuture connectFuture = ioConnector.connect(targetAddress, null, processor, cfg);
    // wait for connection established
    connectFuture.join();

    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.ibasco.agql.examples.SourceRconQueryEx.java

public void testRcon() throws InterruptedException {
    String address = promptInput("Please enter the source server address", true, "", "sourceRconIp");
    int port = Integer.valueOf(promptInput("Please enter the server port", false, "27015", "sourceRconPort"));

    boolean authenticated = false;

    while (!authenticated) {

        serverAddress = new InetSocketAddress(address, port);
        if (!authenticated) {
            password = promptInput("Please enter the rcon password", true, "", "sourceRconPass");
            log.info("Connecting to server {}:{}, with password = {}", address, port,
                    StringUtils.replaceAll(password, ".", "*"));
            SourceRconAuthStatus authStatus = sourceRconClient.authenticate(serverAddress, password).join();
            if (!authStatus.isAuthenticated()) {
                log.error("ERROR: Could not authenticate from server (Reason: {})", authStatus.getReason());
            } else {
                log.debug("Successfully authenticated from server : {}", address);
                authenticated = true;//from ww  w  . j av  a 2  s  .c  o m
            }
        }

        while (authenticated) {
            String command = promptInput("\nEnter rcon command: ", true);
            try {
                sourceRconClient.execute(serverAddress, command).whenComplete(this::handleResponse).join();
            } catch (RconNotYetAuthException e) {
                authenticated = false;
                break;
            } catch (Exception ex) {
                log.error(ex.getMessage(), ex);
            }
        }
    }
}