List of usage examples for java.net InetSocketAddress InetSocketAddress
private InetSocketAddress(int port, String hostname)
From source file:org.dimitrovchi.conf.service.demo.DemoService.java
public DemoService(P parameters) throws IOException { super(parameters); this.httpServer = HttpServer.create(new InetSocketAddress(parameters.host(), parameters.port()), 0); this.httpServer.setExecutor(executor); this.httpServer.createContext("/", new HttpHandler() { @Override// w w w .ja v a 2 s .co m public void handle(HttpExchange he) throws IOException { he.getResponseHeaders().add("Content-Type", "text/plain; charset=utf-8"); final byte[] message = "hello!".getBytes(StandardCharsets.UTF_8); he.sendResponseHeaders(HttpURLConnection.HTTP_OK, message.length); he.getResponseBody().write(message); } }); log.info(ServiceParameterUtils.reflectToString("demoService", parameters)); }
From source file:test.com.wealdtech.jackson.modules.MiscModuleTest.java
@Test public void testDeserInetSocketAddress() throws Exception { final String ser = "\"www.wealdtech.com:12345\""; final InetSocketAddress deser = this.mapper.readValue(ser, InetSocketAddress.class); assertEquals(deser, new InetSocketAddress("www.wealdtech.com", 12345)); }
From source file:com.bitsofproof.supernode.core.DNSDiscovery.java
@Override public List<InetSocketAddress> discover() { log.trace("Discovering network using DNS seed"); int n = 0;// ww w .j a va 2 s. c om List<InetSocketAddress> al = new ArrayList<InetSocketAddress>(); for (String hostName : seedHosts) { log.trace("Obtain addresses from " + hostName); InetAddress[] hostAddresses; try { hostAddresses = InetAddress.getAllByName(hostName); for (InetAddress inetAddress : hostAddresses) { al.add(new InetSocketAddress(inetAddress, chain.getPort())); ++n; } } catch (UnknownHostException e) { } } Collections.shuffle(al); log.trace("Found " + n + " addresses of seed hosts"); return al; }
From source file:com.zf.util.Post_NetNew.java
/** * ?//from www . ja v a2s . c o m * * @param pams * @param ip * @param port * @return * @throws Exception */ public static String pn(Map<String, String> pams, String ip, int port) throws Exception { if (null == pams) { return ""; } InetSocketAddress addr = new InetSocketAddress(ip, port); Proxy proxy = new Proxy(Type.HTTP, addr); String strtmp = "url"; URL url = new URL(pams.get(strtmp)); pams.remove(strtmp); strtmp = "body"; String body = pams.get(strtmp); pams.remove(strtmp); strtmp = "POST"; if (StringUtils.isEmpty(body)) strtmp = "GET"; HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(proxy); httpConn.setConnectTimeout(30000); httpConn.setReadTimeout(30000); httpConn.setUseCaches(false); httpConn.setRequestMethod(strtmp); for (String pam : pams.keySet()) { httpConn.setRequestProperty(pam, pams.get(pam)); } if ("POST".equals(strtmp)) { httpConn.setDoOutput(true); httpConn.setDoInput(true); DataOutputStream dos = new DataOutputStream(httpConn.getOutputStream()); dos.writeBytes(body); dos.flush(); } int resultCode = httpConn.getResponseCode(); StringBuilder sb = new StringBuilder(); sb.append(resultCode).append("\n"); String readLine; InputStream stream; try { stream = httpConn.getInputStream(); } catch (Exception ignored) { stream = httpConn.getErrorStream(); } try { BufferedReader responseReader = new BufferedReader(new InputStreamReader(stream, "UTF-8")); while ((readLine = responseReader.readLine()) != null) { sb.append(readLine).append("\n"); } } catch (Exception ignored) { } return sb.toString(); }
From source file:com.aincc.ber.utils.FakeSocketFactory.java
@Override public Socket connectSocket(Socket sock, String host, int port, InetAddress localAddress, int localPort, HttpParams params) throws IOException { final int connTimeout = HttpConnectionParams.getConnectionTimeout(params); final int soTimeout = HttpConnectionParams.getSoTimeout(params); final InetSocketAddress remoteAddress = new InetSocketAddress(host, port); final SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket()); if ((localAddress != null) || (localPort > 0)) { // we need to bind explicitly if (localPort < 0) { localPort = 0; // indicates "any" }/* ww w.jav a2s . c o m*/ final InetSocketAddress isa = new InetSocketAddress(localAddress, localPort); sslsock.bind(isa); } sslsock.connect(remoteAddress, connTimeout); sslsock.setSoTimeout(soTimeout); return sslsock; }
From source file:ca.viaware.dlna.webinterface.InterfaceServer.java
public InterfaceServer() throws IOException { JSONObject config = SettingsManager.getServerConfig().getJSONObject("webInterface"); this.server = HttpServer.create(new InetSocketAddress(config.getString("host"), config.getInt("port")), 8); }
From source file:com.hellblazer.jackal.testUtil.gossip.GossipTestCfg.java
@Bean(name = "seedHosts") public List<InetSocketAddress> seedHosts() throws UnknownHostException { return asList(new InetSocketAddress("127.0.0.1", getTestPort1()), new InetSocketAddress("127.0.0.1", getTestPort2())); }
From source file:org.echocat.jemoni.carbon.spring.WriterDefinitionParserUnitTest.java
@Test public void test() throws Exception { final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("writerTestBeans.xml", WriterDefinitionParserUnitTest.class); try {/*from w ww . j a v a 2s. c om*/ final CarbonWriter defaultWriter = context.getBean(CarbonWriter.class.getName(), CarbonWriter.class); assertThat(defaultWriter.getAddress(), is(new InetSocketAddress("localhost", 667))); assertThat(defaultWriter.getMaxBufferLifetime(), is(DEFAULT_MAX_BUFFER_LIFETIME)); assertThat(defaultWriter.getCharset(), is(DEFAULT_CHARSET)); final CarbonWriter xxxWriter = context.getBean("xxx", CarbonWriter.class); assertThat(xxxWriter.getAddress(), is(new InetSocketAddress("localhost", 666))); assertThat(xxxWriter.getMaxBufferLifetime(), is(new Duration("666h"))); assertThat(xxxWriter.getCharset(), is(forName("ISO-8859-15"))); } finally { context.close(); } }
From source file:com.jivesoftware.os.jive.utils.http.client.CustomSecureProtocolSocketFactory.java
@Override public Socket createSocket(String host, int port, InetAddress localAddress, int localPort, HttpConnectionParams params) throws IOException { Socket socket = sslSocketFactory.createSocket(); if (localAddress != null && port > 0) { socket.bind(new InetSocketAddress(localAddress, localPort)); }// w ww .j a va2 s . c o m int timeout = params.getSoTimeout(); if (timeout > 0) { socket.setSoTimeout(timeout); } socket.connect(new InetSocketAddress(host, port), params.getConnectionTimeout()); return socket; }
From source file:info.guardianproject.netcipher.NetCipher.java
/** * Set the global HTTP proxy for all new {@link HttpURLConnection}s and * {@link HttpsURLConnection}s that are created after this is called. * <p>// w w w. j a v a 2 s. com * {@link #useTor()} will override this setting. Traffic must be directed * to Tor using the proxy settings, and Orbot has its own proxy settings * for connections that need proxies to work. So if "use Tor" is enabled, * as tested by looking for the static instance of Proxy, then no other * proxy settings are allowed to override the current Tor proxy. * * @param host the IP address for the HTTP proxy to use globally * @param port the port number for the HTTP proxy to use globally */ public static void setProxy(String host, int port) { if (!TextUtils.isEmpty(host) && port > 0) { InetSocketAddress isa = new InetSocketAddress(host, port); setProxy(new Proxy(Proxy.Type.HTTP, isa)); } else if (NetCipher.proxy != ORBOT_HTTP_PROXY) { setProxy(null); } }