从SocketAddress获取端口
/** from n o w j a v a . c o m**/ //package com.nowjava; import java.net.SocketAddress; public class Main { public static Integer getPort(SocketAddress socketAddress) { if (socketAddress == null) { throw new NullPointerException("remoteAddres is null"); } String address = socketAddress.toString(); return Integer.valueOf(address.substring(address.indexOf(':') + 1)); } }