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.velix.jmongo.MongoImpl.java

private static InetSocketAddress parseInetSocketAddress(String host) {
    InetSocketAddress inetAddress;
    int port = DEFAULT_PORT;
    int i = host.indexOf(':');
    if (i > 0) {
        port = Integer.parseInt(host.substring(i + 1).trim());
        inetAddress = new InetSocketAddress(host.substring(0, i).trim(), port);
    } else {/*from  www . j av a 2  s .c  o  m*/
        inetAddress = new InetSocketAddress(host, port);
    }
    return inetAddress;
}

From source file:com.subgraph.vega.internal.http.requests.connection.SocksModeClientConnectionOperator.java

@Override
public void openConnection(OperatedClientConnection conn, HttpHost target, InetAddress local,
        HttpContext context, HttpParams params) throws IOException {
    if (!isSocksMode) {
        super.openConnection(conn, target, local, context, params);
        return;/*from www . jav  a2  s.  c om*/
    }
    final Scheme scheme = schemeRegistry.getScheme(target.getSchemeName());
    final SchemeSocketFactory sf = scheme.getSchemeSocketFactory();

    final int port = scheme.resolvePort(target.getPort());
    Socket sock = sf.createSocket(params);
    conn.opening(sock, target);
    InetSocketAddress remoteAddress = InetSocketAddress.createUnresolved(target.getHostName(), port);
    InetSocketAddress localAddress = null;
    if (local != null) {
        localAddress = new InetSocketAddress(local, 0);
    }
    try {
        Socket connsock = sf.connectSocket(sock, remoteAddress, localAddress, params);
        if (sock != connsock) {
            sock = connsock;
            conn.opening(sock, target);
        }
        prepareSocket(sock, context, params);
        conn.openCompleted(sf.isSecure(sock), params);
        return;
    } catch (ConnectException ex) {
        throw new HttpHostConnectException(target, ex);
    }
}

From source file:de.mpg.escidoc.services.common.util.ProxyHelper.java

/**
 * Returns <code>java.net.Proxy</code> class for <code>java.net.URL.openConnection</code>
 * creation/*from   ww  w.  j a v  a 2 s  . com*/
 *
 * @param url url
 *
 * @throws Exception
 */
public static Proxy getProxy(final String url) {
    Proxy proxy = Proxy.NO_PROXY;

    getProxyProperties();

    if (proxyHost != null) {
        if (!findUrlInNonProxyHosts(url)) {
            SocketAddress proxyAddress = new InetSocketAddress(proxyHost, Integer.valueOf(proxyPort));
            proxy = new Proxy(Proxy.Type.HTTP, proxyAddress);
        }
    }

    return proxy;
}

From source file:com.buaa.cfs.nfs3.PrivilegedNfsGatewayStarter.java

@Override
public void init(DaemonContext context) throws Exception {
    System.err.println("Initializing privileged NFS client socket...");
    NfsConfiguration conf = new NfsConfiguration();
    int clientPort = conf.getInt(NfsConfigKeys.DFS_NFS_REGISTRATION_PORT_KEY,
            NfsConfigKeys.DFS_NFS_REGISTRATION_PORT_DEFAULT);
    if (clientPort < 1 || clientPort > 1023) {
        throw new RuntimeException("Must start privileged NFS server with '"
                + NfsConfigKeys.DFS_NFS_REGISTRATION_PORT_KEY + "' configured to a " + "privileged port.");
    }/*from   w w w.ja v  a 2 s  .co m*/
    registrationSocket = new DatagramSocket(new InetSocketAddress("localhost", clientPort));
    registrationSocket.setReuseAddress(true);
    args = context.getArguments();
}

From source file:com.fuzhouxiu.coretransfer.net.core.TcpSocket.java

/** Creates a new UdpSocket */
public TcpSocket(IpAddress ipaddr, int port, String host) throws java.io.IOException {
    //      socket = new Socket(ipaddr.getInetAddress(), port); modified
    SSLSocketFactory f = (SSLSocketFactory) SSLSocketFactory.getSocketFactory();
    if (host == null)
        socket = new Socket();
    else/* w w  w.  j av a 2 s  .c o  m*/
        socket = f.createSocket();
    if (lock)
        throw new java.io.IOException();
    lock = true;
    try {
        socket.connect(new InetSocketAddress(ipaddr.toString(), port),
                Thread.currentThread().getName().equals("main") ? 1000 : 10000);
    } catch (java.io.IOException e) {
        lock = false;
        throw e;
    }
    if (host != null) {
        HostnameVerifier hv = HttpsURLConnection.getDefaultHostnameVerifier();
        SSLSession s = ((SSLSocket) socket).getSession();
        if (!hv.verify(host, s)) {
            lock = false;
            throw new java.io.IOException();
        }
    }
    lock = false;
}

From source file:org.esigate.cache.MemcachedCacheStorage.java

@Override
public void init(Properties properties) {
    Collection<String> serverStringList = Parameters.MEMCACHED_SERVERS_PROPERTY.getValue(properties);
    if (serverStringList.isEmpty()) {
        throw new ConfigurationException("No memcached server defined. Property '"
                + Parameters.MEMCACHED_SERVERS_PROPERTY + "' must be defined.");
    }//from  w  w  w.j a v a  2 s  .c om
    List<InetSocketAddress> servers = new ArrayList<InetSocketAddress>();
    for (Iterator<String> iterator = serverStringList.iterator(); iterator.hasNext();) {
        String server = iterator.next();
        String[] serverHostPort = server.split(":");
        if (serverHostPort.length != 2) {
            throw new ConfigurationException(
                    "Invalid memcached server: '" + server + "'. Each server must be in format 'host:port'.");
        }
        String host = serverHostPort[0];
        try {
            int port = Integer.parseInt(serverHostPort[1]);
            servers.add(new InetSocketAddress(host, port));
        } catch (NumberFormatException e) {
            throw new ConfigurationException("Invalid memcached server: '" + server
                    + "'. Each server must be in format 'host:port'. Port must be an integer.", e);
        }
    }
    MemcachedClient memcachedClient;
    try {
        memcachedClient = new MemcachedClient(servers);
    } catch (IOException e) {
        throw new ConfigurationException(e);
    }
    CacheConfig cacheConfig = CacheConfigHelper.createCacheConfig(properties);
    setImpl(new MemcachedHttpCacheStorage(memcachedClient, cacheConfig, new MemcachedCacheEntryFactoryImpl(),
            new SHA256KeyHashingScheme()));
}

From source file:org.jclouds.http.httpnio.pool.NioHttpCommandConnectionPoolTest.java

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

From source file:com.bfd.harpc.pool.AvroClientPoolFactory.java

/**
 * ?//from   w  ww. j  av a  2s . c  o m
 */
@SuppressWarnings("unchecked")
@Override
public T makeObject(ServerNode key) throws Exception {
    // ?client
    if (key != null) {
        T t = null;
        if (transceiverMap.containsKey(key)) {
            t = transceiverMap.get(key);
        } else {
            NettyTransceiver nettyTransceiver = new NettyTransceiver(
                    new InetSocketAddress(key.getIp(), key.getPort()), (long) timeout);
            t = (T) SpecificRequestor.getClient(iface, nettyTransceiver);
        }
        return t;
    }
    LOGGER.error("Not find a vilid server!");
    throw new RpcException("Not find a vilid server!");
}

From source file:me.xingrz.prox.udp.UdpProxySession.java

public void send(ByteBuffer buffer) throws IOException {
    serverChannel.register(selector, SelectionKey.OP_READ, this);
    serverChannel.send(buffer, new InetSocketAddress(getRemoteAddress(), getRemotePort()));
}

From source file:com.byteatebit.nbserver.simple.client.SimpleNbClient.java

public void tcpConnect(String remoteHost, int remotePort, IClientSocketChannelHandler socketChannelHandler,
        long timeout) throws IOException {
    if (!initialized.get())
        throw new IllegalStateException("SimpleNbClient must first be initialized via init()");
    SocketChannel socketChannel = SocketChannel.open();
    socketChannel.configureBlocking(false);
    InetSocketAddress address = new InetSocketAddress(remoteHost, remotePort);
    INbContext nbContext = new NbContext(simpleNbService.getSelectorRegistrarBalancer().getSelectorRegistrar(),
            simpleNbService.getScheduler());
    IOTask connectTask = (selectionKey) -> {
        boolean connectionFinished = false;
        try {// w  w  w.  j ava 2 s. co m
            connectionFinished = socketChannel.finishConnect();
        } catch (IOException e) {
            LOG.error("Could not complete socket connection.", e);
        }
        if (!connectionFinished) {
            LOG.error("Could not complete socket connection.  Closing socket channel");
            selectionKey.cancel();
            IOUtils.closeQuietly(socketChannel);
            socketChannelHandler.connectFailed(remoteHost, remotePort);
            return;
        }
        selectionKey.interestOps(selectionKey.interestOps() & ~SelectionKey.OP_CONNECT);
        socketChannelHandler.accept(nbContext, socketChannel);
    };
    IOTimeoutTask timeoutTask = (selectionKey, ops) -> {
        LOG.error("Connect attempt timed out after " + timeout + " ms");
        selectionKey.cancel();
        IOUtils.closeQuietly(socketChannel);
        socketChannelHandler.connectFailed(remoteHost, remotePort);
    };
    nbContext.register(socketChannel, SelectionKey.OP_CONNECT, connectTask, timeoutTask, timeout);
    socketChannel.connect(address);
}