Java examples for Network:IP Address
Creating an InetSocketAddress Object
import java.net.InetSocketAddress; public class Main { public static void main(String[] args) { InetSocketAddress addr1 = new InetSocketAddress("::1", 12889); printSocketAddress(addr1);// www .j a va 2 s .co m InetSocketAddress addr2 = InetSocketAddress.createUnresolved("::1", 12881); printSocketAddress(addr2); } public static void printSocketAddress(InetSocketAddress sAddr) { System.out.println("Socket Address: " + sAddr.getAddress()); System.out.println("Socket Host Name: " + sAddr.getHostName()); System.out.println("Socket Port: " + sAddr.getPort()); System.out.println("isUnresolved(): " + sAddr.isUnresolved()); System.out.println(); } }