What is getServerPort(), getLocalPort(), getRemotePort() ?

These methods are in the HttpServletRequest object.
getRemotePort() – Here server is asking for the remote port. It returns the port of client. In other words the port number on the client from which request came.
getServerPort()- it says to which port was the request originally sent?
getlocalPort()- it says on which port did the request end up?

1 comment:


  1. HELP ME TO GET RIDE OF THIS ERROR

    ERROR:The method getRemotePort() is undefined for the type ServerSocket

    ServerSocket listen = new ServerSocket(0);
    int port2 = listen.getRemotePort();

    new Socket(address1,port2);
    OutputStream os = socket.getOutputStream();
    OutputStreamWriter osw = new OutputStreamWriter(os);
    BufferedWriter bw = new BufferedWriter(osw);
    bw.write(number + "\n");
    System.out.println("Message sent to the client is "+number);
    bw.flush();





    ReplyDelete