当前位置: 首页>>代码示例>>Java>>正文


Java SocketAddress.getClass方法代码示例

本文整理汇总了Java中java.net.SocketAddress.getClass方法的典型用法代码示例。如果您正苦于以下问题:Java SocketAddress.getClass方法的具体用法?Java SocketAddress.getClass怎么用?Java SocketAddress.getClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.net.SocketAddress的用法示例。


在下文中一共展示了SocketAddress.getClass方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: resetNextInetSocketAddress

import java.net.SocketAddress; //导入方法依赖的package包/类
/** Resets {@link #nextInetSocketAddress} to the first option. */
private void resetNextInetSocketAddress(Proxy proxy) throws UnknownHostException {
  socketAddresses = null; // Clear the addresses. Necessary if getAllByName() below throws!

  String socketHost;
  if (proxy.type() == Proxy.Type.DIRECT) {
    socketHost = uri.getHost();
    socketPort = getEffectivePort(uri);
  } else {
    SocketAddress proxyAddress = proxy.address();
    if (!(proxyAddress instanceof InetSocketAddress)) {
      throw new IllegalArgumentException(
          "Proxy.address() is not an " + "InetSocketAddress: " + proxyAddress.getClass());
    }
    InetSocketAddress proxySocketAddress = (InetSocketAddress) proxyAddress;
    socketHost = proxySocketAddress.getHostName();
    socketPort = proxySocketAddress.getPort();
  }

  // Try each address for best behavior in mixed IPv4/IPv6 environments.
  socketAddresses = dns.getAllByName(socketHost);
  nextSocketAddressIndex = 0;
}
 
开发者ID:aabognah,项目名称:LoRaWAN-Smart-Parking,代码行数:24,代码来源:RouteSelector.java

示例2: resetNextInetSocketAddress

import java.net.SocketAddress; //导入方法依赖的package包/类
/** Prepares the socket addresses to attempt for the current proxy or host. */
private void resetNextInetSocketAddress(Proxy proxy) throws IOException {
  // Clear the addresses. Necessary if getAllByName() below throws!
  inetSocketAddresses = new ArrayList<>();

  String socketHost;
  int socketPort;
  if (proxy.type() == Proxy.Type.DIRECT || proxy.type() == Proxy.Type.SOCKS) {
    socketHost = address.url().host();
    socketPort = address.url().port();
  } else {
    SocketAddress proxyAddress = proxy.address();
    if (!(proxyAddress instanceof InetSocketAddress)) {
      throw new IllegalArgumentException(
          "Proxy.address() is not an " + "InetSocketAddress: " + proxyAddress.getClass());
    }
    InetSocketAddress proxySocketAddress = (InetSocketAddress) proxyAddress;
    socketHost = getHostString(proxySocketAddress);
    socketPort = proxySocketAddress.getPort();
  }

  if (socketPort < 1 || socketPort > 65535) {
    throw new SocketException("No route to " + socketHost + ":" + socketPort
        + "; port is out of range");
  }

  if (proxy.type() == Proxy.Type.SOCKS) {
    inetSocketAddresses.add(InetSocketAddress.createUnresolved(socketHost, socketPort));
  } else {
    // Try each address for best behavior in mixed IPv4/IPv6 environments.
    List<InetAddress> addresses = address.dns().lookup(socketHost);
    for (int i = 0, size = addresses.size(); i < size; i++) {
      InetAddress inetAddress = addresses.get(i);
      inetSocketAddresses.add(new InetSocketAddress(inetAddress, socketPort));
    }
  }

  nextInetSocketAddressIndex = 0;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:40,代码来源:RouteSelector.java

示例3: setDefaultRemoteAddress

import java.net.SocketAddress; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
public final void setDefaultRemoteAddress(SocketAddress defaultRemoteAddress) {
    if (defaultRemoteAddress == null) {
        throw new IllegalArgumentException("defaultRemoteAddress");
    }

    if (!getTransportMetadata().getAddressType().isAssignableFrom(defaultRemoteAddress.getClass())) {
        throw new IllegalArgumentException("defaultRemoteAddress type: " + defaultRemoteAddress.getClass()
                + " (expected: " + getTransportMetadata().getAddressType() + ")");
    }
    this.defaultRemoteAddress = defaultRemoteAddress;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:15,代码来源:AbstractIoConnector.java

示例4: resetNextInetSocketAddress

import java.net.SocketAddress; //导入方法依赖的package包/类
private void resetNextInetSocketAddress(Proxy proxy) throws IOException {
    String socketHost;
    int socketPort;
    this.inetSocketAddresses = new ArrayList();
    if (proxy.type() == Type.DIRECT || proxy.type() == Type.SOCKS) {
        socketHost = this.address.getUriHost();
        socketPort = this.address.getUriPort();
    } else {
        SocketAddress proxyAddress = proxy.address();
        if (proxyAddress instanceof InetSocketAddress) {
            InetSocketAddress proxySocketAddress = (InetSocketAddress) proxyAddress;
            socketHost = getHostString(proxySocketAddress);
            socketPort = proxySocketAddress.getPort();
        } else {
            throw new IllegalArgumentException("Proxy.address() is not an InetSocketAddress: " +
                    "" + proxyAddress.getClass());
        }
    }
    if (socketPort < 1 || socketPort > 65535) {
        throw new SocketException("No route to " + socketHost + ":" + socketPort + "; port is" +
                " out of range");
    }
    if (proxy.type() == Type.SOCKS) {
        this.inetSocketAddresses.add(InetSocketAddress.createUnresolved(socketHost,
                socketPort));
    } else {
        List<InetAddress> addresses = this.address.getDns().lookup(socketHost);
        int size = addresses.size();
        for (int i = 0; i < size; i++) {
            this.inetSocketAddresses.add(new InetSocketAddress((InetAddress) addresses.get(i)
                    , socketPort));
        }
    }
    this.nextInetSocketAddressIndex = 0;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:36,代码来源:RouteSelector.java

示例5: resetNextInetSocketAddress

import java.net.SocketAddress; //导入方法依赖的package包/类
/** Prepares the socket addresses to attempt for the current proxy or host. */
private void resetNextInetSocketAddress(Proxy proxy) throws IOException {
  // Clear the addresses. Necessary if getAllByName() below throws!
  inetSocketAddresses = new ArrayList<>();

  String socketHost;
  int socketPort;
  if (proxy.type() == Proxy.Type.DIRECT || proxy.type() == Proxy.Type.SOCKS) {
    socketHost = address.url().host();
    socketPort = address.url().port();
  } else {
    SocketAddress proxyAddress = proxy.address();
    if (!(proxyAddress instanceof InetSocketAddress)) {
      throw new IllegalArgumentException(
          "Proxy.address() is not an " + "InetSocketAddress: " + proxyAddress.getClass());
    }
    InetSocketAddress proxySocketAddress = (InetSocketAddress) proxyAddress;
    socketHost = getHostString(proxySocketAddress);
    socketPort = proxySocketAddress.getPort();
  }

  if (socketPort < 1 || socketPort > 65535) {
    throw new SocketException("No route to " + socketHost + ":" + socketPort
        + "; port is out of range");
  }

  if (proxy.type() == Proxy.Type.SOCKS) {
    inetSocketAddresses.add(InetSocketAddress.createUnresolved(socketHost, socketPort));
  } else {
    eventListener.dnsStart(call, socketHost);

    // Try each address for best behavior in mixed IPv4/IPv6 environments.
    List<InetAddress> addresses = address.dns().lookup(socketHost);
    if (addresses.isEmpty()) {
      throw new UnknownHostException(address.dns() + " returned no addresses for " + socketHost);
    }

    eventListener.dnsEnd(call, socketHost, addresses);

    for (int i = 0, size = addresses.size(); i < size; i++) {
      InetAddress inetAddress = addresses.get(i);
      inetSocketAddresses.add(new InetSocketAddress(inetAddress, socketPort));
    }
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:46,代码来源:RouteSelector.java

示例6: connect

import java.net.SocketAddress; //导入方法依赖的package包/类
/**
 * Like {@link NetUtils#connect(Socket, SocketAddress, int)} but
 * also takes a local address and port to bind the socket to. 
 * 
 * @param socket
 * @param endpoint the remote address
 * @param localAddr the local address to bind the socket to
 * @param timeout timeout in milliseconds
 */
public static void connect(Socket socket, 
                           SocketAddress endpoint,
                           SocketAddress localAddr,
                           int timeout) throws IOException {
  if (socket == null || endpoint == null || timeout < 0) {
    throw new IllegalArgumentException("Illegal argument for connect()");
  }
  
  SocketChannel ch = socket.getChannel();
  
  if (localAddr != null) {
    Class localClass = localAddr.getClass();
    Class remoteClass = endpoint.getClass();
    Preconditions.checkArgument(localClass.equals(remoteClass),
        "Local address %s must be of same family as remote address %s.",
        localAddr, endpoint);
    socket.bind(localAddr);
  }

  try {
    if (ch == null) {
      // let the default implementation handle it.
      socket.connect(endpoint, timeout);
    } else {
      SocketIOWithTimeout.connect(ch, endpoint, timeout);
    }
  } catch (SocketTimeoutException ste) {
    throw new ConnectTimeoutException(ste.getMessage());
  }

  // There is a very rare case allowed by the TCP specification, such that
  // if we are trying to connect to an endpoint on the local machine,
  // and we end up choosing an ephemeral port equal to the destination port,
  // we will actually end up getting connected to ourself (ie any data we
  // send just comes right back). This is only possible if the target
  // daemon is down, so we'll treat it like connection refused.
  if (socket.getLocalPort() == socket.getPort() &&
      socket.getLocalAddress().equals(socket.getInetAddress())) {
    LOG.info("Detected a loopback TCP socket, disconnecting it");
    socket.close();
    throw new ConnectException(
      "Localhost targeted connection resulted in a loopback. " +
      "No daemon is listening on the target port.");
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:55,代码来源:NetUtils.java


注:本文中的java.net.SocketAddress.getClass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。