Java InetSocketAddress.getPort() Method: Retrieve Port Number
In Java, the 'getPort()' method of the 'InetSocketAddress' class is used to get the port number of the endpoint represented by this 'InetSocketAddress' object. The port number is an integer value ranging from 0 to 65535, which identifies a specific process running on a host machine.
Example usage:
InetSocketAddress address = new InetSocketAddress('localhost', 8080);
int port = address.getPort();
System.out.println('Port number: ' + port);
This code creates a new 'InetSocketAddress' object with the hostname 'localhost' and port number 8080, and then retrieves the port number using the 'getPort()' method. The output will be:
Port number: 8080
原文地址: https://www.cveoy.top/t/topic/okXZ 著作权归作者所有。请勿转载和采集!