Cannot bind to port, even though tcpview says it's not in use
Every so often when trying to start up my Java appserver on my WinXP box, it fails to start with an "Address already in use" error when trying to listen on a port. The usual solution for me is to fire up tcpview (from sysinternals), see what's using that port, killing that process, then trying again. Works 99% of the time.
The remaining 1%, however, this doesn't work. The appserver insists the port (e.g. port 1099, not that it matters) is in use, and tcpview insists equally strongly that it isn't.
The appserver is just delegating the server socket creation to windows, so I can't see it being a java-specific issue, although I'm happy to be corrected on that.
What gives? Is tcpview missing out some corner case? Is there a better tool that would help me diagnose these situations?
Solution 1:
Weird. To pinpoint the problem, you could try
netstat -an
That should also list all ports in use. If it disagrees, the problem might be with tcpview. Otherwise, you'd have to look elsewhere.
Solution 2:
additionally, you could try
netstat -ano
to find the ProcessID and to narrow it down a bit, assuming your port is 8191
netstat -ano | find "8191"