Here you can find the source of getLocalAddress(Socket socket)
public static String getLocalAddress(Socket socket)
//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; } }