Here you can find the source of getPort(SocketAddress socketAddress)
public static Integer getPort(SocketAddress socketAddress)
//package com.java2s; //License from project: Open Source License import java.net.SocketAddress; public class Main { public static Integer getPort(SocketAddress socketAddress) { if (socketAddress == null) { return 0; }//from www . j ava2 s. co m String address = socketAddress.toString(); return Integer.valueOf(address.substring(address.indexOf(':') + 1)); } }