InetSocketAddress getPort Example
InetSocketAddress class getPort example. This example shows you how to use getPort method.
InetSocketAddress class getPort example. public final int getPort() Gets the port number.
Here is the code
/*
* @ # GetPort.java
* A class repersenting use to GetPort method
* of InetSocketAddress class in java.net package
* version 23 June 2008
* author Rose India
*/
import java.net.*;
public class GetPort {
public static void main(String[] args) throws Exception {
//Get local host.
InetAddress inetAddress = InetAddress.getLocalHost();
InetSocketAddress inetSocketAddress = new InetSocketAddress(inetAddress, 1313);
//Gets InetAddress.
System.out.println("port number " + inetSocketAddress.getPort());
}
} |
|