Tabnine Logo
InetSocketAddress.getPort
Code IndexAdd Tabnine to your IDE (free)

How to use
getPort
method
in
java.net.InetSocketAddress

Best Java code snippets using java.net.InetSocketAddress.getPort (Showing top 20 results out of 13,590)

Refine searchRefine arrow

  • InetSocketAddress.getAddress
  • InetAddress.getHostAddress
  • InetSocketAddress.getHostName
  • InetSocketAddress.<init>
  • InetSocketAddress.getHostString
origin: apache/incubator-dubbo

public static String toAddressString(InetSocketAddress address) {
  return address.getAddress().getHostAddress() + ":" + address.getPort();
}
origin: apache/zookeeper

public String getClientAddress() {
  if (null == peer.clientAddr) {
    return "";
  }
  return peer.clientAddr.getHostString() + ":"
      + peer.clientAddr.getPort();
}
origin: alibaba/canal

public MysqlConnector(InetSocketAddress address, String username, String password){
  String addr = address.getHostString();
  int port = address.getPort();
  this.address = new InetSocketAddress(addr, port);
  this.username = username;
  this.password = password;
}
origin: redisson/redisson

private InetSocketAddress createInetSocketAddress(InetSocketAddress resolved, String host) {
  byte[] addr = NetUtil.createByteArrayFromIpAddressString(resolved.getAddress().getHostAddress());
  try {
    return new InetSocketAddress(InetAddress.getByAddress(host, addr), resolved.getPort());
  } catch (UnknownHostException e) {
    throw new RuntimeException(e);
  }
}

origin: apache/ignite

/** {@inheritDoc} */
@Override public Collection<InetSocketAddress> getExternalAddresses(InetSocketAddress addr)
  throws IgniteCheckedException {
  InetSocketAddress inetSockAddr = inetSockAddrMap.get(addr);
  if (inetSockAddr != null)
    return Collections.singletonList(inetSockAddr);
  InetAddress inetAddr = inetAddrMap.get(addr.getAddress());
  if (inetAddr != null)
    return Collections.singletonList(new InetSocketAddress(inetAddr, addr.getPort()));
  return Collections.emptyList();
}
origin: redisson/redisson

  public static InetSocketAddress computeRemoteAddr(InetSocketAddress remoteAddr, InetSocketAddress osRemoteAddr) {
    if (osRemoteAddr != null) {
      if (PlatformDependent.javaVersion() >= 7) {
        try {
          // Only try to construct a new InetSocketAddress if we using java >= 7 as getHostString() does not
          // exists in earlier releases and so the retrieval of the hostname could block the EventLoop if a
          // reverse lookup would be needed.
          return new InetSocketAddress(InetAddress.getByAddress(remoteAddr.getHostString(),
              osRemoteAddr.getAddress().getAddress()),
              osRemoteAddr.getPort());
        } catch (UnknownHostException ignore) {
          // Should never happen but fallback to osRemoteAddr anyway.
        }
      }
      return osRemoteAddr;
    }
    return remoteAddr;
  }
}
origin: apache/zookeeper

private static InetSocketAddress getClientAddress(Map<Long, QuorumServer> quorumPeers, long myid, int clientPort)
    throws IOException {
  QuorumServer quorumServer = quorumPeers.get(myid);
  if (null == quorumServer) {
    throw new IOException("No QuorumServer correspoding to myid " + myid);
  }
  if (null == quorumServer.clientAddr) {
    return new InetSocketAddress(clientPort);
  }
  if (quorumServer.clientAddr.getPort() != clientPort) {
    throw new IOException("QuorumServer port " + quorumServer.clientAddr.getPort()
        + " does not match with given port " + clientPort);
  }
  return quorumServer.clientAddr;
}
origin: apache/zookeeper

  public static String formatInetAddr(InetSocketAddress addr) {
    InetAddress ia = addr.getAddress();

    if (ia == null) {
      return String.format("%s:%s", addr.getHostString(), addr.getPort());
    }

    if (ia instanceof Inet6Address) {
      return String.format("[%s]:%s", ia.getHostAddress(), addr.getPort());
    } else {
      return String.format("%s:%s", ia.getHostAddress(), addr.getPort());
    }
  }
}
origin: square/okhttp

@Override public Object getParameter(String name) {
 if (name.equals(ConnRouteParams.DEFAULT_PROXY)) {
  Proxy proxy = client.proxy();
  if (proxy == null) {
   return null;
  }
  InetSocketAddress address = (InetSocketAddress) proxy.address();
  return new HttpHost(address.getHostName(), address.getPort());
 }
 throw new IllegalArgumentException(name);
}
origin: wildfly/wildfly

  @Override
  public Object run() throws UnknownHostException {
    final InetSocketAddress resolvedAddress = new InetSocketAddress(InetAddress.getByName(address.getHostName()), address.getPort());
    exchange.setDestinationAddress(resolvedAddress);
    return null;
  }
});
origin: redisson/redisson

@Override
public void serialize(InetSocketAddress value, JsonGenerator jgen, SerializerProvider provider) throws IOException
{
  InetAddress addr = value.getAddress();
  String str = addr == null ? value.getHostName() : addr.toString().trim();
  int ix = str.indexOf('/');
  if (ix >= 0) {
    if (ix == 0) { // missing host name; use address
      str = addr instanceof Inet6Address
          ? "[" + str.substring(1) + "]" // bracket IPv6 addresses with
          : str.substring(1);
    } else { // otherwise use name
      str = str.substring(0, ix);
    }
  }
  jgen.writeString(str + ":" + value.getPort());
}
origin: redisson/redisson

@Override
public MasterSlaveEntry getEntry(InetSocketAddress address) {
  for (MasterSlaveEntry entry : client2entry.values()) {
    InetSocketAddress addr = entry.getClient().getAddr();
    if (addr.getAddress().equals(address.getAddress()) && addr.getPort() == address.getPort()) {
      return entry;
    }
  }
  return null;
}

origin: apache/flink

/**
 * Encodes an IP address and port to be included in URL. in particular, this method makes
 * sure that IPv6 addresses have the proper formatting to be included in URLs.
 *
 * @param address The socket address with the IP address and port.
 * @return The proper URL string encoded IP address and port.
 */
public static String socketAddressToUrlString(InetSocketAddress address) {
  if (address.isUnresolved()) {
    throw new IllegalArgumentException("Address cannot be resolved: " + address.getHostString());
  }
  return ipAddressAndPortToUrlString(address.getAddress(), address.getPort());
}
origin: redisson/redisson

private InetSocketAddress createInetSocketAddress(InetSocketAddress resolved, String host) {
  byte[] addr = NetUtil.createByteArrayFromIpAddressString(resolved.getAddress().getHostAddress());
  try {
    return new InetSocketAddress(InetAddress.getByAddress(host, addr), resolved.getPort());
  } catch (UnknownHostException e) {
    throw new RuntimeException(e);
  }
}

origin: apache/incubator-dubbo

public static String toAddressString(InetSocketAddress address) {
  return address.getAddress().getHostAddress() + ":" + address.getPort();
}
origin: real-logic/aeron

private static InetSocketAddress getMulticastControlAddress(final InetSocketAddress endpointAddress)
  throws UnknownHostException
{
  final byte[] addressAsBytes = endpointAddress.getAddress().getAddress();
  validateDataAddress(addressAsBytes);
  addressAsBytes[addressAsBytes.length - 1]++;
  return new InetSocketAddress(getByAddress(addressAsBytes), endpointAddress.getPort());
}
origin: wildfly/wildfly

  public static InetSocketAddress computeRemoteAddr(InetSocketAddress remoteAddr, InetSocketAddress osRemoteAddr) {
    if (osRemoteAddr != null) {
      if (PlatformDependent.javaVersion() >= 7) {
        try {
          // Only try to construct a new InetSocketAddress if we using java >= 7 as getHostString() does not
          // exists in earlier releases and so the retrieval of the hostname could block the EventLoop if a
          // reverse lookup would be needed.
          return new InetSocketAddress(InetAddress.getByAddress(remoteAddr.getHostString(),
              osRemoteAddr.getAddress().getAddress()),
              osRemoteAddr.getPort());
        } catch (UnknownHostException ignore) {
          // Should never happen but fallback to osRemoteAddr anyway.
        }
      }
      return osRemoteAddr;
    }
    return remoteAddr;
  }
}
origin: netty/netty

  @Override
  public void operationComplete(Future<List<InetAddress>> future) throws Exception {
    if (future.isSuccess()) {
      List<InetAddress> inetAddresses = future.getNow();
      List<InetSocketAddress> socketAddresses =
          new ArrayList<InetSocketAddress>(inetAddresses.size());
      for (InetAddress inetAddress : inetAddresses) {
        socketAddresses.add(new InetSocketAddress(inetAddress, unresolvedAddress.getPort()));
      }
      promise.setSuccess(socketAddresses);
    } else {
      promise.setFailure(future.cause());
    }
  }
});
origin: apache/zookeeper

private InetSocketAddress resolve(InetSocketAddress address) {
  try {
    String curHostString = address.getHostString();
    List<InetAddress> resolvedAddresses = new ArrayList<>(Arrays.asList(this.resolver.getAllByName(curHostString)));
    if (resolvedAddresses.isEmpty()) {
      return address;
    }
    Collections.shuffle(resolvedAddresses);
    return new InetSocketAddress(resolvedAddresses.get(0), address.getPort());
  } catch (UnknownHostException e) {
    LOG.error("Unable to resolve address: {}", address.toString(), e);
    return address;
  }
}
origin: apache/flink

private void send(final String name, final String value) {
  try {
    String formatted = String.format("%s:%s|g", name, value);
    byte[] data = formatted.getBytes(StandardCharsets.UTF_8);
    socket.send(new DatagramPacket(data, data.length, this.address));
  }
  catch (IOException e) {
    LOG.error("unable to send packet to statsd at '{}:{}'", address.getHostName(), address.getPort());
  }
}
java.netInetSocketAddressgetPort

Javadoc

Returns this socket address' port.

Popular methods of InetSocketAddress

  • <init>
    Creates a socket endpoint with the given port number port and address. The range for valid port numb
  • getAddress
    Returns this socket address' address.
  • getHostName
    Returns the hostname, doing a reverse DNS lookup on the InetAddress if no hostname string was provid
  • getHostString
    Returns the hostname if known, or the result of InetAddress.getHostAddress. Unlike #getHostName, thi
  • createUnresolved
    Creates an InetSocketAddress without trying to resolve the hostname into an InetAddress. The address
  • toString
    Returns a string containing the address (or the hostname for an unresolved InetSocketAddress) and po
  • isUnresolved
    Returns whether this socket address is unresolved or not.
  • equals
    Compares two socket endpoints and returns true if they are equal. Two socket endpoints are equal if
  • hashCode
    Returns a hashcode for this socket address.

Popular in Java

  • Finding current android device location
  • onCreateOptionsMenu (Activity)
  • setRequestProperty (URLConnection)
  • putExtra (Intent)
  • Container (java.awt)
    A generic Abstract Window Toolkit(AWT) container object is a component that can contain other AWT co
  • FlowLayout (java.awt)
    A flow layout arranges components in a left-to-right flow, much like lines of text in a paragraph. F
  • HashSet (java.util)
    HashSet is an implementation of a Set. All optional operations (adding and removing) are supported.
  • Map (java.util)
    A Map is a data structure consisting of a set of keys and values in which each key is mapped to a si
  • ServletException (javax.servlet)
    Defines a general exception a servlet can throw when it encounters difficulty.
  • HttpServlet (javax.servlet.http)
    Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A sub
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now