Example #1
0
  /**
   * If the socket is already bound this returns the local SocketAddress, otherwise null
   *
   * @since 1.4
   */
  public SocketAddress getLocalSocketAddress() {
    InetAddress addr = getLocalAddress();

    if (addr == null) return null;

    return new InetSocketAddress(addr, impl.getLocalPort());
  }
Example #2
0
  /**
   * Returns the local port number to which this socket is bound. If this socket is not connected,
   * then -1 is returned.
   *
   * @return The local port
   */
  public int getLocalPort() {
    if (impl != null) return impl.getLocalPort();

    return -1;
  }