java.net.Socket.tryAllAddresses()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(14.5k)|赞(0)|评价(0)|浏览(198)

本文整理了Java中java.net.Socket.tryAllAddresses()方法的一些代码示例,展示了Socket.tryAllAddresses()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Socket.tryAllAddresses()方法的具体详情如下:
包路径:java.net.Socket
类名称:Socket
方法名:tryAllAddresses

Socket.tryAllAddresses介绍

[英]Tries to connect a socket to all IP addresses of the given hostname.
[中]尝试将套接字连接到给定主机名的所有IP地址。

代码示例

代码示例来源:origin: robovm/robovm

/**
 * Creates a new streaming socket connected to the target host specified by
 * the parameters {@code dstName} and {@code dstPort}. On the local endpoint
 * the socket is bound to the given address {@code localAddress} on port
 * {@code localPort}. If {@code host} is {@code null} a loopback address is used to connect to.
 *
 * <p>This implementation tries each IP address for the given hostname (in
 * <a href="http://www.ietf.org/rfc/rfc3484.txt">RFC 3484</a> order)
 * until it either connects successfully or it exhausts the set.
 *
 * @param dstName
 *            the target host name or IP address to connect to.
 * @param dstPort
 *            the port on the target host to connect to.
 * @param localAddress
 *            the address on the local host to bind to.
 * @param localPort
 *            the port on the local host to bind to.
 * @throws UnknownHostException
 *             if the host name could not be resolved into an IP address.
 * @throws IOException
 *             if an error occurs while creating the socket.
 */
public Socket(String dstName, int dstPort, InetAddress localAddress, int localPort) throws IOException {
  this();
  tryAllAddresses(dstName, dstPort, localAddress, localPort, true);
}

代码示例来源:origin: robovm/robovm

/**
 * Creates a new streaming or datagram socket connected to the target host
 * specified by the parameters {@code hostName} and {@code port}. The socket
 * is bound to any available port on the local host.
 *
 * <p>This implementation tries each IP address for the given hostname (in
 * <a href="http://www.ietf.org/rfc/rfc3484.txt">RFC 3484</a> order)
 * until it either connects successfully or it exhausts the set.
 *
 * @param hostName
 *            the target host name or IP address to connect to.
 * @param port
 *            the port on the target host to connect to.
 * @param streaming
 *            if {@code true} a streaming socket is returned, a datagram
 *            socket otherwise.
 * @throws UnknownHostException
 *             if the host name could not be resolved into an IP address.
 * @throws IOException
 *             if an error occurs while creating the socket.
 * @deprecated Use {@code Socket(String, int)} instead of this for streaming
 *             sockets or an appropriate constructor of {@code
 *             DatagramSocket} for UDP transport.
 */
@Deprecated
public Socket(String hostName, int port, boolean streaming) throws IOException {
  this();
  tryAllAddresses(hostName, port, null, 0, streaming);
}

代码示例来源:origin: MobiVM/robovm

/**
 * Creates a new streaming socket connected to the target host specified by
 * the parameters {@code dstName} and {@code dstPort}. On the local endpoint
 * the socket is bound to the given address {@code localAddress} on port
 * {@code localPort}. If {@code host} is {@code null} a loopback address is used to connect to.
 *
 * <p>This implementation tries each IP address for the given hostname (in
 * <a href="http://www.ietf.org/rfc/rfc3484.txt">RFC 3484</a> order)
 * until it either connects successfully or it exhausts the set.
 *
 * @param dstName
 *            the target host name or IP address to connect to.
 * @param dstPort
 *            the port on the target host to connect to.
 * @param localAddress
 *            the address on the local host to bind to.
 * @param localPort
 *            the port on the local host to bind to.
 * @throws UnknownHostException
 *             if the host name could not be resolved into an IP address.
 * @throws IOException
 *             if an error occurs while creating the socket.
 */
public Socket(String dstName, int dstPort, InetAddress localAddress, int localPort) throws IOException {
  this();
  tryAllAddresses(dstName, dstPort, localAddress, localPort, true);
}

代码示例来源:origin: ibinti/bugvm

/**
 * Creates a new streaming socket connected to the target host specified by
 * the parameters {@code dstName} and {@code dstPort}. On the local endpoint
 * the socket is bound to the given address {@code localAddress} on port
 * {@code localPort}. If {@code host} is {@code null} a loopback address is used to connect to.
 *
 * <p>This implementation tries each IP address for the given hostname (in
 * <a href="http://www.ietf.org/rfc/rfc3484.txt">RFC 3484</a> order)
 * until it either connects successfully or it exhausts the set.
 *
 * @param dstName
 *            the target host name or IP address to connect to.
 * @param dstPort
 *            the port on the target host to connect to.
 * @param localAddress
 *            the address on the local host to bind to.
 * @param localPort
 *            the port on the local host to bind to.
 * @throws UnknownHostException
 *             if the host name could not be resolved into an IP address.
 * @throws IOException
 *             if an error occurs while creating the socket.
 */
public Socket(String dstName, int dstPort, InetAddress localAddress, int localPort) throws IOException {
  this();
  tryAllAddresses(dstName, dstPort, localAddress, localPort, true);
}

代码示例来源:origin: com.gluonhq/robovm-rt

/**
 * Creates a new streaming socket connected to the target host specified by
 * the parameters {@code dstName} and {@code dstPort}. On the local endpoint
 * the socket is bound to the given address {@code localAddress} on port
 * {@code localPort}. If {@code host} is {@code null} a loopback address is used to connect to.
 *
 * <p>This implementation tries each IP address for the given hostname (in
 * <a href="http://www.ietf.org/rfc/rfc3484.txt">RFC 3484</a> order)
 * until it either connects successfully or it exhausts the set.
 *
 * @param dstName
 *            the target host name or IP address to connect to.
 * @param dstPort
 *            the port on the target host to connect to.
 * @param localAddress
 *            the address on the local host to bind to.
 * @param localPort
 *            the port on the local host to bind to.
 * @throws UnknownHostException
 *             if the host name could not be resolved into an IP address.
 * @throws IOException
 *             if an error occurs while creating the socket.
 */
public Socket(String dstName, int dstPort, InetAddress localAddress, int localPort) throws IOException {
  this();
  tryAllAddresses(dstName, dstPort, localAddress, localPort, true);
}

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

/**
 * Creates a new streaming socket connected to the target host specified by
 * the parameters {@code dstName} and {@code dstPort}. On the local endpoint
 * the socket is bound to the given address {@code localAddress} on port
 * {@code localPort}. If {@code host} is {@code null} a loopback address is used to connect to.
 *
 * <p>This implementation tries each IP address for the given hostname (in
 * <a href="http://www.ietf.org/rfc/rfc3484.txt">RFC 3484</a> order)
 * until it either connects successfully or it exhausts the set.
 *
 * @param dstName
 *            the target host name or IP address to connect to.
 * @param dstPort
 *            the port on the target host to connect to.
 * @param localAddress
 *            the address on the local host to bind to.
 * @param localPort
 *            the port on the local host to bind to.
 * @throws UnknownHostException
 *             if the host name could not be resolved into an IP address.
 * @throws IOException
 *             if an error occurs while creating the socket.
 */
public Socket(String dstName, int dstPort, InetAddress localAddress, int localPort) throws IOException {
  this();
  tryAllAddresses(dstName, dstPort, localAddress, localPort, true);
}

代码示例来源:origin: com.bugvm/bugvm-rt

/**
 * Creates a new streaming socket connected to the target host specified by
 * the parameters {@code dstName} and {@code dstPort}. On the local endpoint
 * the socket is bound to the given address {@code localAddress} on port
 * {@code localPort}. If {@code host} is {@code null} a loopback address is used to connect to.
 *
 * <p>This implementation tries each IP address for the given hostname (in
 * <a href="http://www.ietf.org/rfc/rfc3484.txt">RFC 3484</a> order)
 * until it either connects successfully or it exhausts the set.
 *
 * @param dstName
 *            the target host name or IP address to connect to.
 * @param dstPort
 *            the port on the target host to connect to.
 * @param localAddress
 *            the address on the local host to bind to.
 * @param localPort
 *            the port on the local host to bind to.
 * @throws UnknownHostException
 *             if the host name could not be resolved into an IP address.
 * @throws IOException
 *             if an error occurs while creating the socket.
 */
public Socket(String dstName, int dstPort, InetAddress localAddress, int localPort) throws IOException {
  this();
  tryAllAddresses(dstName, dstPort, localAddress, localPort, true);
}

代码示例来源:origin: FlexoVM/flexovm

/**
 * Creates a new streaming socket connected to the target host specified by
 * the parameters {@code dstName} and {@code dstPort}. On the local endpoint
 * the socket is bound to the given address {@code localAddress} on port
 * {@code localPort}. If {@code host} is {@code null} a loopback address is used to connect to.
 *
 * <p>This implementation tries each IP address for the given hostname (in
 * <a href="http://www.ietf.org/rfc/rfc3484.txt">RFC 3484</a> order)
 * until it either connects successfully or it exhausts the set.
 *
 * @param dstName
 *            the target host name or IP address to connect to.
 * @param dstPort
 *            the port on the target host to connect to.
 * @param localAddress
 *            the address on the local host to bind to.
 * @param localPort
 *            the port on the local host to bind to.
 * @throws UnknownHostException
 *             if the host name could not be resolved into an IP address.
 * @throws IOException
 *             if an error occurs while creating the socket.
 */
public Socket(String dstName, int dstPort, InetAddress localAddress, int localPort) throws IOException {
  this();
  tryAllAddresses(dstName, dstPort, localAddress, localPort, true);
}

代码示例来源:origin: MobiVM/robovm

/**
 * Creates a new streaming or datagram socket connected to the target host
 * specified by the parameters {@code hostName} and {@code port}. The socket
 * is bound to any available port on the local host.
 *
 * <p>This implementation tries each IP address for the given hostname (in
 * <a href="http://www.ietf.org/rfc/rfc3484.txt">RFC 3484</a> order)
 * until it either connects successfully or it exhausts the set.
 *
 * @param hostName
 *            the target host name or IP address to connect to.
 * @param port
 *            the port on the target host to connect to.
 * @param streaming
 *            if {@code true} a streaming socket is returned, a datagram
 *            socket otherwise.
 * @throws UnknownHostException
 *             if the host name could not be resolved into an IP address.
 * @throws IOException
 *             if an error occurs while creating the socket.
 * @deprecated Use {@code Socket(String, int)} instead of this for streaming
 *             sockets or an appropriate constructor of {@code
 *             DatagramSocket} for UDP transport.
 */
@Deprecated
public Socket(String hostName, int port, boolean streaming) throws IOException {
  this();
  tryAllAddresses(hostName, port, null, 0, streaming);
}

代码示例来源:origin: ibinti/bugvm

/**
 * Creates a new streaming or datagram socket connected to the target host
 * specified by the parameters {@code hostName} and {@code port}. The socket
 * is bound to any available port on the local host.
 *
 * <p>This implementation tries each IP address for the given hostname (in
 * <a href="http://www.ietf.org/rfc/rfc3484.txt">RFC 3484</a> order)
 * until it either connects successfully or it exhausts the set.
 *
 * @param hostName
 *            the target host name or IP address to connect to.
 * @param port
 *            the port on the target host to connect to.
 * @param streaming
 *            if {@code true} a streaming socket is returned, a datagram
 *            socket otherwise.
 * @throws UnknownHostException
 *             if the host name could not be resolved into an IP address.
 * @throws IOException
 *             if an error occurs while creating the socket.
 * @deprecated Use {@code Socket(String, int)} instead of this for streaming
 *             sockets or an appropriate constructor of {@code
 *             DatagramSocket} for UDP transport.
 */
@Deprecated
public Socket(String hostName, int port, boolean streaming) throws IOException {
  this();
  tryAllAddresses(hostName, port, null, 0, streaming);
}

代码示例来源:origin: com.gluonhq/robovm-rt

/**
 * Creates a new streaming or datagram socket connected to the target host
 * specified by the parameters {@code hostName} and {@code port}. The socket
 * is bound to any available port on the local host.
 *
 * <p>This implementation tries each IP address for the given hostname (in
 * <a href="http://www.ietf.org/rfc/rfc3484.txt">RFC 3484</a> order)
 * until it either connects successfully or it exhausts the set.
 *
 * @param hostName
 *            the target host name or IP address to connect to.
 * @param port
 *            the port on the target host to connect to.
 * @param streaming
 *            if {@code true} a streaming socket is returned, a datagram
 *            socket otherwise.
 * @throws UnknownHostException
 *             if the host name could not be resolved into an IP address.
 * @throws IOException
 *             if an error occurs while creating the socket.
 * @deprecated Use {@code Socket(String, int)} instead of this for streaming
 *             sockets or an appropriate constructor of {@code
 *             DatagramSocket} for UDP transport.
 */
@Deprecated
public Socket(String hostName, int port, boolean streaming) throws IOException {
  this();
  tryAllAddresses(hostName, port, null, 0, streaming);
}

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

/**
 * Creates a new streaming or datagram socket connected to the target host
 * specified by the parameters {@code hostName} and {@code port}. The socket
 * is bound to any available port on the local host.
 *
 * <p>This implementation tries each IP address for the given hostname (in
 * <a href="http://www.ietf.org/rfc/rfc3484.txt">RFC 3484</a> order)
 * until it either connects successfully or it exhausts the set.
 *
 * @param hostName
 *            the target host name or IP address to connect to.
 * @param port
 *            the port on the target host to connect to.
 * @param streaming
 *            if {@code true} a streaming socket is returned, a datagram
 *            socket otherwise.
 * @throws UnknownHostException
 *             if the host name could not be resolved into an IP address.
 * @throws IOException
 *             if an error occurs while creating the socket.
 * @deprecated Use {@code Socket(String, int)} instead of this for streaming
 *             sockets or an appropriate constructor of {@code
 *             DatagramSocket} for UDP transport.
 */
@Deprecated
public Socket(String hostName, int port, boolean streaming) throws IOException {
  this();
  tryAllAddresses(hostName, port, null, 0, streaming);
}

代码示例来源:origin: com.bugvm/bugvm-rt

/**
 * Creates a new streaming or datagram socket connected to the target host
 * specified by the parameters {@code hostName} and {@code port}. The socket
 * is bound to any available port on the local host.
 *
 * <p>This implementation tries each IP address for the given hostname (in
 * <a href="http://www.ietf.org/rfc/rfc3484.txt">RFC 3484</a> order)
 * until it either connects successfully or it exhausts the set.
 *
 * @param hostName
 *            the target host name or IP address to connect to.
 * @param port
 *            the port on the target host to connect to.
 * @param streaming
 *            if {@code true} a streaming socket is returned, a datagram
 *            socket otherwise.
 * @throws UnknownHostException
 *             if the host name could not be resolved into an IP address.
 * @throws IOException
 *             if an error occurs while creating the socket.
 * @deprecated Use {@code Socket(String, int)} instead of this for streaming
 *             sockets or an appropriate constructor of {@code
 *             DatagramSocket} for UDP transport.
 */
@Deprecated
public Socket(String hostName, int port, boolean streaming) throws IOException {
  this();
  tryAllAddresses(hostName, port, null, 0, streaming);
}

代码示例来源:origin: FlexoVM/flexovm

/**
 * Creates a new streaming or datagram socket connected to the target host
 * specified by the parameters {@code hostName} and {@code port}. The socket
 * is bound to any available port on the local host.
 *
 * <p>This implementation tries each IP address for the given hostname (in
 * <a href="http://www.ietf.org/rfc/rfc3484.txt">RFC 3484</a> order)
 * until it either connects successfully or it exhausts the set.
 *
 * @param hostName
 *            the target host name or IP address to connect to.
 * @param port
 *            the port on the target host to connect to.
 * @param streaming
 *            if {@code true} a streaming socket is returned, a datagram
 *            socket otherwise.
 * @throws UnknownHostException
 *             if the host name could not be resolved into an IP address.
 * @throws IOException
 *             if an error occurs while creating the socket.
 * @deprecated Use {@code Socket(String, int)} instead of this for streaming
 *             sockets or an appropriate constructor of {@code
 *             DatagramSocket} for UDP transport.
 */
@Deprecated
public Socket(String hostName, int port, boolean streaming) throws IOException {
  this();
  tryAllAddresses(hostName, port, null, 0, streaming);
}

相关文章