集册 Java实例教程 从SocketAddress获取端口

从SocketAddress获取端口

欢马劈雪     最近更新时间:2020-01-02 10:19:05

469
从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));

    }

}