Java examples for Network:Network Address
get Port from SocketAddress
//package com.java2s; import java.net.SocketAddress; public class Main { public static Integer getPort(SocketAddress socketAddress) { if (socketAddress == null) { throw new NullPointerException("remoteAddres is null"); }/*from w ww. jav a2 s.com*/ String address = socketAddress.toString(); return Integer.valueOf(address.substring(address.indexOf(':') + 1)); } }