Javatpoint Logo
Javatpoint Logo

Java ServerSocket getLocalPort() Method

The getLocalPort() method of ServerSocket class is used to give the port number of the server on which this socket is listening. If the socket was bound before being closed, then this method will continue to return the port number after the socket is closed.

Syntax

Parameter:

No Parameter.

Returns:

The port number to which this socket is listening or -1 if the socket is not bound yet.

Example 1

ServerApplication:

ClientApplication

Java ServerSocket getLocalPort() Method
Java ServerSocket getLocalPort() Method

Example 2

ServerApplication

clientApplication:

Output:

Java ServerSocket getLocalPort() Method
Java ServerSocket getLocalPort() Method
Next TopicJava ServerSocket





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA