Using NIO features ( like ServerSocketChannel, Selector) introduced in
java 1.4 you can handle multiple requests ( I think this can be done by ServerSocket as well, but not tested
).
I created sample program which accepts multiple requests, new
thread is assigned per request( this can be optimised using ThreadPool), Thread just sleeps for 10 seconds (just to demo that i can handle multiple requests).
Stephan van Hulst wrote:If a client with some IP address connects to a server on a specific port, a socket is created. If the same IP address does this again, it will fail because the socket already exists.
If another IP address connects to the same port, it will create a different socket. But this is no different from handling separate requests on different ports.
I even tried to
test what Stephen already quoted. I initially opened multiple tabs in firefox everyone pointing to
http://localhost:8085/test and surprised, firefox normally opens one http connection at time. I then tried to use
telnet localhost 8085 and found than I can open 2 simultaneous telnet connection and nothing is blocked.
I suspected about firefox behaviour and then i just modified url in every tab to include request param ( just to make sure every tab will submit different http requests) eg,
http://localhost:8085/test?1...12 . I opened 12 tabs everyone with different parameters and i found that firefox use to create 6 parallel connections and after closing first connection it submits next connection (but max 6 at a time).
Look likes for same url, instead of creating multiple http connection, browser used to tunnel http requests on same connection and max 6 can be the limitation set by browser for any host/site.
I even verified this limitation of 6 by creating single html page with 6 iframes and hit at same time from both firefox and chrome browser. I can see now 12 active connections in tcpmonitor tool (i used tcpmonitor here to track timing and request and response).