Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

getServerPort() vs getLocalPort()

843841Dec 24 2007 — edited Jan 23 2008
In HFSJ you can read: "The difference between getLocalPort() and getServerPort() is more subtle -
getServerPort() says, 'to which port was the request originally sent' while getLocalPort() says, 'on which port
did the request end up ?' Yes, there is a difference, because although the requests are sent to a single port
(where the server is listening), the server turns around and finds a different local port for each thread, so that
the app can handle multiple clients at the same time."

I don't understand why the app wouldn't be able to handle multiple clients at the same time without having
different port numbers for each thread ...

And when it happens, does it mean that container creates socket for each client and container then starts
listening on those ports ? It would mean that container needs some kind of connection manager so it knows
what client connects on which port and forwards to which threads. So I see it this way (assuming there is only
tomcat standalone) : client connects to tomcat on port let's say 8080. Container creates/allocates a thread,
loads the servlet, creates another socket with port let's say 8081, passes the request through the thread to
servlet and it generates the output. Next time the same client sends request, it uses port 8081 on which the
container is now listening and the story continues ... Am I right here ?? :/

Also, would it be done that way for efficiency ?


Cheers,

Adrian Sosialuk
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 20 2008
Added on Dec 24 2007
3 comments
620 views