Socket getLocalPort Example

Socket class getLocalPort example. This example shows you how to use getLocalPort method.


Socket class getLocalPort example. public int getLocalPort() Returns the local port to which this socket is bound.

Here is the code
/*
 * @ # GetLocalPort.java
 * A class repersenting use to getLocalAddress method 
 * of NumberFormat class in java.text package
 * version 17 June 2008
 * author Rose India 
 */

import java.net.*;

public class GetLocalPort {

    public static void main(String args[]) throws Exception {

        Socket socket = new Socket();

        //Connects this socket to the server.
        socket.connect(new InetSocketAddress("192.168.10.80"9090));
        
        System.out.println(socket.getLocalPort());

        //close socket
        socket.close();
    }
}

Output
36134

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US