private void connectToAddress(InetAddress address, int port, int timeout) throws IOException { if (address.isAnyLocalAddress()) { doConnect(InetAddress.getLocalHost(), port, timeout); } else { doConnect(address, port, timeout); } }
/** * Binds the socket to the specified address of the specified local port. * * @param address the address * @param port the port */ protected synchronized void bind(InetAddress address, int lport) throws IOException { socketBind(address, lport); if (socket != null) socket.setBound(); if (serverSocket != null) serverSocket.setBound(); if (address.isAnyLocalAddress()) { anyLocalBoundAddr = address; } }
/** * Creates a socket and connects it to the specified port on the specified host. * * @param host the specified host * @param port the specified port */ protected void connect(String host, int port) throws UnknownHostException, IOException { IOException pending = null; try { InetAddress address = InetAddress.getByName(host); try { connectToAddress(address, port, timeout); return; } catch (IOException e) { pending = e; } } catch (UnknownHostException e) { pending = e; } // everything failed close(); throw pending; }