List of usage examples for java.net InetSocketAddress InetSocketAddress
private InetSocketAddress(int port, String hostname)
From source file:org.mycard.net.network.HttpConnection.java
/*** * Opens the connection to a http server * * @return the opened low level connection * @throws IOException if the connection fails for any reason. *//* w w w . ja v a2s.co m*/ @Override AndroidHttpClientConnection openConnection(Request req) throws IOException { // Update the certificate info (connection not secure - set to null) //EventHandler eventHandler = req.getEventHandler(); //mCertificate = null; //eventHandler.certificate(mCertificate); AndroidHttpClientConnection conn = new AndroidHttpClientConnection(); BasicHttpParams params = new BasicHttpParams(); Socket sock = new Socket(); sock.connect(new InetSocketAddress(mHost.getHostName(), mHost.getPort()), 20 * 1000); params.setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8192); conn.bind(sock, params); return conn; }
From source file:example.springdata.redis.test.util.RequiresRedisServer.java
@Override protected void before() throws Throwable { try (Socket socket = new Socket()) { socket.setTcpNoDelay(true);//from w ww.j a v a2 s . com socket.setSoLinger(true, 0); socket.connect(new InetSocketAddress(host, port), timeout); } catch (Exception e) { throw new AssumptionViolatedException( String.format("Seems as redis is not running at %s:%s.", host, port), e); } }
From source file:org.jclouds.http.httpnio.pool.NioHttpCommandConnectionPoolTest.java
public void testConstructorGoodPort() throws Exception { NioHttpCommandConnectionPool pool = new NioHttpCommandConnectionPool(null, null, null, null, createNiceMock(AsyncNHttpClientHandler.class), null, createNiceMock(HttpParams.class), URI.create("http://localhost:80")); assertEquals(pool.getTarget(), new InetSocketAddress("localhost", 80)); }
From source file:com.chess.genesis.net.SocketClient.java
private synchronized void connect() throws IOException { if (socket.isConnected()) return;/* w w w. j a va2 s .c o m*/ socket.connect(new InetSocketAddress("genesischess.com", 8338)); socket.setSoTimeout(8000); socket.setKeepAlive(true); input = new BufferedReader(new InputStreamReader(socket.getInputStream())); output = socket.getOutputStream(); loginHash = input.readLine().trim(); }
From source file:com.sun.faban.driver.transport.hc3.AboveTimedSSLSocketFactory.java
public Socket createSocket(String host, int port, InetAddress localAddress, int localPort) throws IOException { Socket socket = new TimedSocketWrapper(sslFactory.createSocket()); InetSocketAddress endpoint = new InetSocketAddress(host, port); socket.bind(new InetSocketAddress(localAddress, localPort)); socket.connect(endpoint);// w w w . jav a2s. c om return socket; }
From source file:org.lispmob.noroot.IPC.java
public IPC(LISPmobVPNService vpn_service) { this.vpn_service = vpn_service; notifications = new Notifications(this.vpn_service); try {// w w w . j a va2s . com ipc_channel = DatagramChannel.open(); ipc_channel.socket().bind(new InetSocketAddress(ipc_addr, ipc_src_port)); ipc_channel.connect(new InetSocketAddress(ipc_addr, ipc_dst_port)); } catch (Exception e) { e.printStackTrace(); } ipc_thread = new Thread(this, "IPC"); }
From source file:org.springframework.social.openidconnect.api.impl.GAECompatibleClientHttpRequestFactorySelector.java
public static ClientHttpRequestFactory getRequestFactory() { Properties properties = System.getProperties(); String proxyHost = properties.getProperty("http.proxyHost"); int proxyPort = properties.containsKey("http.proxyPort") ? Integer.valueOf(properties.getProperty("http.proxyPort")) : 80;/*from w w w.j a va 2 s. c om*/ if (HTTP_COMPONENTS_AVAILABLE) { HttpClientBuilder httpClientBuilder = HttpClients.custom(); if (proxyHost != null) { HttpHost proxy = new HttpHost(proxyHost, proxyPort); httpClientBuilder.setProxy(proxy); } return HttpComponentsClientRequestFactoryCreator.createRequestFactory(httpClientBuilder.build(), proxyHost, proxyPort); } else { SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); if (proxyHost != null) { requestFactory.setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort))); } return requestFactory; } }
From source file:com.supernovapps.audio.jstreamsourcer.ShoutcastV1.java
public boolean start(Socket sock) { try {//from ww w. j ava2 s . co m this.sock = sock; sock.connect(new InetSocketAddress(host, port), 5000); sock.setSendBufferSize(64 * 1024); out = sock.getOutputStream(); PrintWriter output = writeAuthentication(); InputStreamReader isr = new InputStreamReader(sock.getInputStream()); BufferedReader in = new BufferedReader(isr); String line = in.readLine(); if (line == null || !line.contains("OK")) { if (listener != null) { listener.onError("Connection / Authentification error"); } return false; } while (line != null && line.length() > 0) { line = in.readLine(); } writeHeaders(output); } catch (Exception e) { e.printStackTrace(); try { if (sock != null) sock.close(); } catch (IOException e1) { e1.printStackTrace(); } if (listener != null) { listener.onError("Connection / Authentification error"); } return false; } started = true; if (listener != null) { listener.onConnected(); } return true; }
From source file:com.acmemotors.gf.Main.java
@Bean PoolFactoryBean poolFactoryBean(@Value("${gf.server.port}") int serverPort, @Value("${gf.server.host}") String host) throws Exception { PoolFactoryBean factoryBean = new PoolFactoryBean(); factoryBean.setName("my-pool"); factoryBean.setServers(Collections.singletonList(new InetSocketAddress(host, serverPort))); factoryBean.afterPropertiesSet();/*from w w w.j a v a 2 s. com*/ return factoryBean; }
From source file:com.ottogroup.bi.spqr.metrics.MetricsReporterFactory.java
/** * Attaches a {@link GraphiteReporter} to provided {@link MetricsHandler} * @param metricsHandler/*from w ww.j a v a 2 s. c om*/ * @param id * @param period * @param host * @param port * @throws RequiredInputMissingException */ private static void attachGraphiteReporter(final MetricsHandler metricsHandler, final String id, final int period, final String host, final int port) throws RequiredInputMissingException { ////////////////////////////////////////////////////////////////////////// // validate input if (StringUtils.isBlank(id)) throw new RequiredInputMissingException("Missing required metric reporter id"); if (metricsHandler == null) throw new RequiredInputMissingException("Missing required metrics handler"); if (StringUtils.isBlank(host)) throw new RequiredInputMissingException("Missing required graphite host"); if (port < 0) throw new RequiredInputMissingException("Missing required graphite port"); ////////////////////////////////////////////////////////////////////////// final Graphite graphite = new Graphite(new InetSocketAddress(host, port)); final GraphiteReporter reporter = GraphiteReporter.forRegistry(metricsHandler.getRegistry()) .convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).filter(MetricFilter.ALL) .build(graphite); reporter.start((period > 0 ? period : 1), TimeUnit.SECONDS); metricsHandler.addScheduledReporter(id, reporter); }