Socket getPort Example

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


Socket class getPort example. public int getPort() Returns the remote port to which this socket is connected.

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

import java.net.*;

public class GetPort {

    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.getPort());

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

Output
9090

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

HOME | COPYRIGHT | CONTACT US