Java examples for Network:Network Address
local SocketAddress
//package com.java2s; import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.SocketAddress; public class Main { public static void main(String[] argv) throws Exception { int port = 2; System.out.println(localAddress(port)); }// www . ja va 2s . c om private static final byte[] IPV4_LOCALHOST = new byte[] { 127, 0, 0, 1 }; public static SocketAddress localAddress(final int port) throws IOException { return new InetSocketAddress( InetAddress.getByAddress(IPV4_LOCALHOST), port); } }