get IP from SocketAddress - Java Network

Java examples for Network:IP Address

Description

get IP from SocketAddress

Demo Code


//package com.java2s;
import java.net.SocketAddress;

public class Main {
    public static String getIP(SocketAddress socketAddress) {
        if (socketAddress == null) {
            throw new NullPointerException("remoteAddres is null");
        }/*  w  w w . j  a v  a  2 s .  c o  m*/
        String address = socketAddress.toString();
        return address.substring(1, address.indexOf(':'));
    }
}

Related Tutorials