Java Socket Address Get getLocalAddress(Socket socket)

Here you can find the source of getLocalAddress(Socket socket)

Description

get Local Address

License

Open Source License

Declaration

public static String getLocalAddress(Socket socket) 

Method Source Code

//package com.java2s;
/*//  w  ww.ja  v a 2s. c  o m
 * Copyright (c) Mirth Corporation. All rights reserved.
 * 
 * http://www.mirthcorp.com
 * 
 * The software in this package is published under the terms of the MPL license a copy of which has
 * been included with this distribution in the LICENSE.txt file.
 */

import java.net.Socket;

public class Main {
    public static String getLocalAddress(Socket socket) {
        String localAddress = socket == null
                || socket.getLocalAddress() == null ? "" : socket
                .getLocalAddress().toString() + ":" + socket.getLocalPort();

        // If addresses begin with a slash "/", remove it.
        if (localAddress.startsWith("/")) {
            localAddress = localAddress.substring(1);
        }

        return localAddress;
    }
}

Related

  1. getInetSocketTransportAddressConstructor()
  2. getIp(SocketAddress socketAddress)
  3. getIpAddress(Socket socket)
  4. getIpAddress(SocketAddress sa)
  5. getIpAsString(SocketAddress address)
  6. getLocalSocketAddress(String host, int port)
  7. getNetworkVersion(InetSocketAddress address)
  8. getOffsettedAddress(InetSocketAddress isa, int offset)
  9. getPort(InetSocketAddress socket)