• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Difference between getRemotePort() and getServerPort()

 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
GetServerPort returns the port where server is listening and getRemotePort returns with the client port. But aren't,t those same thing ?
 
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Janki. nice to see you.

let me try to explain.

getServerPort is simple to understand. it is the port where your server is listening for incoming connections. Simple. basically your server(server as in hardware) has an ip address. on that machine there can be many software/processes listening on different ports. out of that one is your server(server as in software application) . that server is running on some port which you assign. for tomcat for e.g. default port is 8080.

now getRemotePort. this referes to port on which client is running. client as in browser or it can be any desktop application as well. now to communicate with the server which is running on 8080 say our desktop application or browser will open a port or acquire a port on the client machine. this port is not some well known port or reserved ports(although it can be). such ports are called ephemeral ports. from wikipedia

The range 49152–65535 - above the registered ports - contains dynamic or private ports that cannot be registered with IANA.[106] This range is used for custom or temporary purposes and for automatic allocation of ephemeral ports



it can be possible that your desktop client/browser gets some specific port from IANA(which is authority for the same) or it can open its own port and use it for temporary purposes.

now when your server returns the response it goes back to the port from which the request came.
i hope you understood it. Please post in case of doubts
Regards
 
Janki Shah
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Gurpeet. Got the point. You explained it very well.
reply
    Bookmark Topic Watch Topic
  • New Topic