List of usage examples for java.net InetSocketAddress InetSocketAddress
private InetSocketAddress(int port, String hostname)
From source file:ProxyAuthenticator.java
private static void downloadFromUrl(String urlString) throws Exception { InputStream is = null;//from w w w . j ava 2 s .c o m FileOutputStream fos = null; URL url = new URL(urlString); System.out.println("Reading..." + url); Authenticator.setDefault(new ProxyAuthenticator("username", "password")); SocketAddress addr = new InetSocketAddress("your proxyserver ip address", 80); Proxy proxy = new Proxy(Proxy.Type.HTTP, addr); HttpURLConnection conn = (HttpURLConnection) url.openConnection(proxy); is = conn.getInputStream(); String filename = getOutputFileName(url); fos = new FileOutputStream(filename); byte[] readData = new byte[1024]; int i = is.read(readData); while (i != -1) { fos.write(readData, 0, i); i = is.read(readData); } System.out.println("Created file: " + filename); System.out.println("Completed"); }
From source file:Main.java
protected static InetSocketAddress deserialiseAddress(DataInputStream is) throws IOException { byte[] bytes = deserialiseByteArray(is, 16); int port = is.readShort() & 0xffff; return (new InetSocketAddress(InetAddress.getByAddress(bytes), port)); }
From source file:com.google.code.fqueue.memcached.StartNewQueue.java
public static void newQueueInstance(int port) { InetSocketAddress addr = new InetSocketAddress("0.0.0.0", port); int idle = -1; boolean verbose = false; MemCacheDaemon.memcachedVersion = "0.1"; final MemCacheDaemon<LocalCacheElement> daemon = new MemCacheDaemon<LocalCacheElement>(); CacheStorage<String, LocalCacheElement> storage = new FSStorage(); CacheImpl cacheImpl = new CacheImpl(storage); daemon.setCache(cacheImpl);//from w ww . j a v a2s . c o m daemon.setAddr(addr); daemon.setBinary(false); daemon.setIdleTime(idle); daemon.setVerbose(verbose); daemon.start(); log.info("\r\n\t FQueue instance started,port:" + port + " [version 0.1] \r\n\t\t\t Copyright (C) 2011 sunli"); Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { public void run() { if (daemon != null && daemon.isRunning()) daemon.stop(); log.info("shutdown server"); } })); }
From source file:Test.java
private static void serverStart() { try {/*from ww w . j a va 2 s .c om*/ InetSocketAddress hostAddress = new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 2583); AsynchronousServerSocketChannel serverSocketChannel = AsynchronousServerSocketChannel.open() .bind(hostAddress); Future<AsynchronousSocketChannel> serverFuture = serverSocketChannel.accept(); final AsynchronousSocketChannel clientSocket = serverFuture.get(); if ((clientSocket != null) && (clientSocket.isOpen())) { InputStream connectionInputStream = Channels.newInputStream(clientSocket); ObjectInputStream ois = null; ois = new ObjectInputStream(connectionInputStream); while (true) { Object object = ois.readObject(); if (object.equals("EOF")) { clientSocket.close(); break; } System.out.println("Received :" + object); } ois.close(); connectionInputStream.close(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:gridool.util.net.SocketUtils.java
public static Socket openSocket(InetAddress addr, int port, int connectTimeout, long pollDelay, int maxRetry) throws IOException { SocketAddress sockAddr = new InetSocketAddress(addr, port); return openSocket(sockAddr, connectTimeout, pollDelay, maxRetry); }
From source file:org.openbaton.nfvo.vnfm_reg.impl.register.RestRegister.java
private static boolean pingHost(String host, int port, int timeout) { try (Socket socket = new Socket()) { socket.connect(new InetSocketAddress(host, port), timeout); return true; } catch (IOException ignored) { return false; // Either timeout or unreachable or failed DNS lookup. }/*from ww w. j a va 2 s . co m*/ }
From source file:com.gargoylesoftware.htmlunit.httpclient.SocksConnectionSocketFactory.java
static Socket createSocketWithSocksProxy(final HttpHost socksProxy) { final InetSocketAddress address = new InetSocketAddress(socksProxy.getHostName(), socksProxy.getPort()); final Proxy proxy = new Proxy(Proxy.Type.SOCKS, address); return new Socket(proxy); }
From source file:gridool.util.net.SocketUtils.java
public static Socket openSocket(String host, int port, int connectTimeout, long pollDelay, int maxRetry) throws IOException { SocketAddress sockAddr = new InetSocketAddress(host, port); return openSocket(sockAddr, connectTimeout, pollDelay, maxRetry); }
From source file:com.nokia.dempsy.mpcluster.zookeeper.ZookeeperTestServer.java
public static int findNextPort() throws IOException { // find an unused ehpemeral port InetSocketAddress inetSocketAddress = new InetSocketAddress(InetAddress.getLocalHost(), 0); ServerSocket serverSocket = new ServerSocket(); serverSocket.setReuseAddress(true); // this allows the server port to be bound to even if it's in TIME_WAIT serverSocket.bind(inetSocketAddress); port = serverSocket.getLocalPort();/* w w w . java 2 s .co m*/ serverSocket.close(); return port; }
From source file:com.clustercontrol.winsyslog.UdpSender.java
/** * ??/*w ww.j a v a2s. c om*/ * @param configValue ?? */ public static void init(String configValue) { // ? // ex)192.168.0.1:24001,192.168.0.2:24001 List<InetSocketAddress> sockets = new ArrayList<InetSocketAddress>(); if (configValue != null && configValue.length() > 0) { String[] targetsArray = configValue.split(","); for (String target : targetsArray) { String[] address = target.split(":"); if (address.length != 2) { log.warn("illegal configuration value line \"syslog.send.targets\":" + target); continue; } try { InetSocketAddress socketAddress = new InetSocketAddress(address[0].trim(), Integer.parseInt(address[1].trim())); sockets.add(socketAddress); } catch (Exception e) { log.warn("illegal configuration value line \"syslog.send.targets\":" + target, e); } } } else { log.warn("configuration value \"syslog.send.targets\" is not defined."); } toAddresses = sockets.toArray(new InetSocketAddress[0]); }