Primary transport getting method. Tries to connect and test UDP Transport.
If UDP failed, tries TCP transport. If it fails, too, throws IOException

@param addr
@return Transport instance
@throws IOException
559781
public static Transport getTransport(SocketAddress addr) throws IOException {
        Transport trans;
        try {
            log.debug("Connecting TCP");
            trans = TCPInstance(addr);
            if (!trans.test()) {
                throw new IOException("Agent is unreachable via TCP");
            }
            return trans;
        } catch (IOException e) {
            log.info("Can't connect TCP transport for host: " + addr.toString(), e);
            try {
                log.debug("Connecting UDP");
                trans = UDPInstance(addr);
                if (!trans.test()) {
                    throw new IOException("Agent is unreachable via UDP");
                }
                return trans;
            } catch (IOException ex) {
                log.info("Can't connect UDP transport for host: " + addr.toString(), ex);
                throw ex;
            }
        }
    }
740377
public static UNIXSocket connectTo(UNIXSocketAddress addr) throws IOException {
	UNIXSocket socket = newInstance();
	socket.connect(addr);
	return socket;
    }
776022
@Override
    public TTransport connect(TTransport transport, String serverHost, String asUser) throws TTransportException {
        int maxBufferSize = type.getMaxBufferSize(storm_conf);
        // create a framed transport
        TTransport conn = new TFramedTransport(transport, maxBufferSize);

        // connect
        conn.open();
        LOG.debug("Simple client transport has been established");

        return conn;
    }
968845
public static int getFreePort(int defaultPort) throws IOException {
    try (
        ServerSocket serverSocket = new ServerSocket(defaultPort)
    ) {
      return serverSocket.getLocalPort();
    } catch (IOException e) {
      return getFreePort();
    }
  }
643542
public IPRangeNode findAddr(InetAddress addr) {

	for (IPRangeNode c: this.list) {

	    IPRangeNode result = c.findAddr(addr);

	    if (result != null) return result;
	}

	return null;
    }
546286
public static UNIXServerSocket bindOn(final UNIXSocketAddress addr) throws IOException {
	UNIXServerSocket socket = newInstance();
	socket.bind(addr);
	return socket;
    }
761519
private boolean open() throws IOException
    {
        assert (fd == null);

        //  Resolve the address
        if (addr == null) {
            throw new IOException("Null address");
        }

        addr.resolve(options.ipv6);

        Address.IZAddress resolved = addr.resolved();
        if (resolved == null) {
            throw new IOException("Address not resolved");
        }

        SocketAddress sa = resolved.address();
        if (sa == null) {
            throw new IOException("Socket address not resolved");
        }

        //  Create the socket.
        if (options.selectorChooser == null) {
            fd = SocketChannel.open();
        }
        else {
            fd = options.selectorChooser.choose(resolved, options).openSocketChannel();
        }

        // On some systems, IPv4 mapping in IPv6 sockets is disabled by default.
        // Switch it on in such cases.
        // The method enableIpv4Mapping is empty. Still to be written
        if (resolved.family() == StandardProtocolFamily.INET6) {
            TcpUtils.enableIpv4Mapping(fd);
        }

        // Set the socket to non-blocking mode so that we get async connect().
        TcpUtils.unblockSocket(fd);

        //  Set the socket buffer limits for the underlying socket.
        if (options.sndbuf != 0) {
            TcpUtils.setTcpSendBuffer(fd, options.sndbuf);
        }
        if (options.rcvbuf != 0) {
            TcpUtils.setTcpReceiveBuffer(fd, options.rcvbuf);
        }

        // Set the IP Type-Of-Service priority for this socket
        if (options.tos != 0) {
            TcpUtils.setIpTypeOfService(fd, options.tos);
        }

        // TODO V4 Set a source address for conversations
        if (resolved.sourceAddress() != null) {
            //            SocketChannel bind = channel.bind(resolved.sourceAddress());
            //            if (bind == null) {
            //                return false;
            //            }
        }

        //  Connect to the remote peer.
        boolean rc;
        try {
            rc = fd.connect(sa);
            if (rc) {
                //  Connect was successful immediately.
            }
            else {
                //  Translate error codes indicating asynchronous connect has been
                //  launched to a uniform EINPROGRESS.
                errno.set(ZError.EINPROGRESS);
            }
        }
        catch (IllegalArgumentException e) {
            // this will happen if sa is bad.  Address validation is not documented but
            // I've found that IAE is thrown in openjdk as well as on android.
            throw new IOException(e.getMessage(), e);
        }

        return rc;

    }
1370542
def translate(self, addr):
        
        # get family of this address so we translate to the same
        family = socket.getaddrinfo(addr, 0, socket.AF_UNSPEC, socket.SOCK_STREAM)[0][0]
        host = socket.getfqdn(addr)
        for a in socket.getaddrinfo(host, 0, family, socket.SOCK_STREAM):
            try:
                return a[4][0]
            except Exception:
                pass
        return addr
973766
public static TcpClientTransport create(InetSocketAddress address) {
    Objects.requireNonNull(address, "address must not be null");

    TcpClient tcpClient = TcpClient.create().addressSupplier(() -> address);
    return create(tcpClient);
  }
312613
public void setSocketAddr(String name, InetSocketAddress addr) {
		set(name, NetUtils.getHostPortString(addr));
	}
429304
public EpollServerSocketChannelConfig setIpTransparent(boolean transparent) {
        try {
            ((EpollServerSocketChannel) channel).socket.setIpTransparent(transparent);
            return this;
        } catch (IOException e) {
            throw new ChannelException(e);
        }
    }
1035937
def address(addr):
    

    if ':' in addr:
        # Using rpartition here means we should be able to support
        # IPv6, but only with a strict syntax
        host, _sep, port = addr.rpartition(':')

        # Convert the port to a number
        try:
            port = int(port)
        except ValueError:
            raise ValueError("invalid port number %r" % port)

        addr = (host, port)

    return addr
1038291
def get_transport_target(cls, instance, timeout, retries):
        '''
        
        '''
        if "ip_address" not in instance:
            raise Exception("An IP address needs to be specified")
        ip_address = instance["ip_address"]
        port = int(instance.get("port", 161))  # Default SNMP port
        return hlapi.UdpTransportTarget((ip_address, port), timeout=timeout, retries=retries)
642753
@Override
  public Transport newInstance(final String hostAddress,
                               final int port,
                               final EStage<TransportEvent> clientStage,
                               final EStage<TransportEvent> serverStage,
                               final int numberOfTries,
                               final int retryTimeout) {
    try {
      TcpPortProvider tcpPortProvider = Tang.Factory.getTang().newInjector().getInstance(TcpPortProvider.class);
      return newInstance(hostAddress, port, clientStage,
              serverStage, numberOfTries, retryTimeout, tcpPortProvider);
    } catch (final InjectionException e) {
      throw new RuntimeException(e);
    }
  }
119872
public Map getSettings(String addr) {

	try {

	    return this.getSettings(InetAddress.getByName(addr));
	}
	catch (Throwable t) {
	    ExceptionUtil.rethrowIfNecessary(t);
	}

	return EMPTY;
    }
1177750
public static synchronized NIOTcpMultiplexer getMultiplexer() throws PacketTransportException
	{
		if (multiplexer == null)
			multiplexer = new NIOTcpMultiplexer(getSettings(),true);
		return multiplexer;
	}
735566
def _getaddr (self, ifname, func):
        """"""
        try:
            result = self._ioctl(func, self._getifreq(ifname))
        except IOError as msg:
            log.warn(LOG_CHECK,
                  "error getting addr for interface %r: %s", ifname, msg)
            return None
        return socket.inet_ntoa(result[20:24])