/** * Binds <code>socket</socket> to <code>endpoint</code>. If the * port in <code>endpoint</code> is zero, then a port is chosen * from this port range. If the port range is [0,0], then a free * port is chosen by the OS. * * @throws IOException if the bind operation fails, or if the * socket is already bound. */ public int bind(ServerSocket socket, InetSocketAddress endpoint) throws IOException { int port = endpoint.getPort(); PortRange range = (port > 0) ? new PortRange(port) : this; return range.bind(socket, endpoint.getAddress(), 0); }
/** * Returns the tcp port range. * <p> * It first checks the 'GLOBUS_TCP_PORT_RANGE' environment variable. If that * system property is not set then 'org.globus.tcp.port.range' system * property is checked. Returns an open range otherwise. * <p> * The port range is in the following form: minport, maxport */ public static PortRange getGlobusTcpPortRange() { String value = System.getenv("GLOBUS_TCP_PORT_RANGE"); if (value != null) { return valueOf(value); } value = System.getProperty("org.globus.tcp.port.range"); if (value != null) { return valueOf(value); } return new PortRange(0); }
/** * Binds <code>socket</socket> to the wildcard * <code>address</code>. A port is chosen from this port range. If * the port range is [0,0], then a free port is chosen by the OS. * * @throws IOException if the bind operation fails, or if the * socket is already bound. */ public int bind(Socket socket) throws IOException { return bind(socket, (InetAddress) null); }
/** * Behave like setPassive(ANY_PORT, DEFAULT_QUEUE) **/ public HostPort setPassive() throws IOException { return setPassive(new PortRange(0), DEFAULT_QUEUE); }
/** * Binds <code>socket</socket> to <code>address</code>. A port is * chosen from this port range. If the port range is [0,0], then a * free port is chosen by the OS. * * @throws IOException if the bind operation fails, or if the * socket is already bound. */ public int bind(ServerSocket socket, InetAddress address, int backlog) throws IOException { int start = random(); int port = start; do { try { socket.bind(new InetSocketAddress(address, port), backlog); return port; } catch (BindException e) { } port = succ(port); } while (port != start); throw new BindException("No free port within range"); }
/** * Binds <code>socket</socket> to <code>address</code>. A port is * chosen from this port range. If the port range is [0,0], then a * free port is chosen by the OS. * * @throws IOException if the bind operation fails, or if the * socket is already bound. */ public int bind(ServerSocket socket, InetAddress address) throws IOException { return bind(socket, address, 0); }
/** * Parse a port range. A port range consists of either a single * integer, or two integers separated by either a comma or a * colon. * * The bounds must be between 0 and 65535, both inclusive. * * @return The port range represented by <code>s</code>. Returns * the range [0,0] if <code>s</code> is null or empty. */ public static PortRange valueOf(String s) throws IllegalArgumentException { try { Matcher m = FORMAT.matcher(s); if (!m.matches()) { throw new IllegalArgumentException("Invalid range: " + s); } String lowString = m.group(1); String highString = m.group(2); int low = Integer.parseInt(lowString); int high = (highString == null) ? low : Integer.parseInt(highString); return new PortRange(low, high); } catch (NumberFormatException e) { throw new IllegalArgumentException("Invalid range: " + s); } }
/** * Binds <code>socket</socket> to <code>address</code>. A port is * chosen from this port range. If the port range is [0,0], then a * free port is chosen by the OS. * * @throws IOException if the bind operation fails, or if the * socket is already bound. */ public int bind(Socket socket, InetAddress address) throws IOException { int start = random(); int port = start; do { try { socket.bind(new InetSocketAddress(address, port)); return port; } catch (BindException e) { } port = succ(port); } while (port != start); throw new BindException("No free port within range"); }
/** * Binds <code>socket</socket> to <code>endpoint</code>. If the * port in <code>endpoint</code> is zero, then a port is chosen * from this port range. If the port range is [0,0], then a free * port is chosen by the OS. * * @throws IOException if the bind operation fails, or if the * socket is already bound. */ public int bind(Socket socket, InetSocketAddress endpoint) throws IOException { int port = endpoint.getPort(); PortRange range = (port > 0) ? new PortRange(port) : this; return range.bind(socket, endpoint.getAddress()); }
/** * Binds <code>socket</socket> to the wildcard * <code>address</code>. A port is chosen from this port range. If * the port range is [0,0], then a free port is chosen by the OS. * * @throws IOException if the bind operation fails, or if the * socket is already bound. */ public int bind(ServerSocket socket) throws IOException { return bind(socket, (InetAddress) null); }
public HostPortList setStripedPassive(PortRange range, int queue) throws IOException { // remove existing sockets, if any socketPool.flush(); if (serverSocket == null) { ServerSocketChannel channel = ServerSocketChannel.open(); range.bind(channel.socket(), queue); serverSocket = channel.socket(); } gSession.serverMode = GridFTPSession.SERVER_EPAS; gSession.serverAddressList = new HostPortList(); String address = NetworkUtils.getLocalAddress(InetAddress.getByName(remoteControlChannel.getHost())).getHostAddress(); int localPort = serverSocket.getLocalPort(); HostPort hp = null; if (remoteControlChannel.isIPv6()) { String version = HostPort6.getIPAddressVersion(address); hp = new HostPort6(version, address, localPort); } else { hp = new HostPort(address, localPort); } gSession.serverAddressList.add(hp); logger.debug("started single striped passive server at port {}", gSession.serverAddressList.get(0).getPort()); return gSession.serverAddressList; }
/** * Binds <code>socket</socket> to the wildcard * <code>address</code>. A port is chosen from this port range. If * the port range is [0,0], then a free port is chosen by the OS. * * @throws IOException if the bind operation fails, or if the * socket is already bound. */ public int bind(ServerSocket socket, int backlog) throws IOException { return bind(socket, (InetAddress) null, backlog); }
range.bind(channel.socket(), queue); serverSocket = channel.socket();