I recently found out about SO_REUSEADDR
on windows; and that tomcat uses this by default.
I did a small test to find out what happens when another process is also listening to the same port. The other process in my case was netcat
. The results were surprising:
- Irrespective of whether I start
nc
(netcat
) first ortomcat
, the response if from tomcat - If I stop tomcat with its
bin/tomcat.bat
it also kills thenc
process - If I stop tomcat by killing the process then nc is able to respond to the next connection
What magic is this? How is tomcat always able to grab incoming request? Is this (tomcat will serve all connections even if other processes are listening) guaranteed behavior? I cannot imagine how it can be guaranteed but thought to ask.