Here you can find the source of getLocalAddress(int port)
public static InetSocketAddress getLocalAddress(int port) throws UnknownHostException
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.UnknownHostException; public class Main { public static InetSocketAddress getLocalAddress(int port) throws UnknownHostException { String ipAddress = InetAddress.getLocalHost().getHostAddress(); return new InetSocketAddress(ipAddress, port); }//from w w w.jav a2 s .c o m }