C++ – Unable to bind to local port – WSAEADDRINUSE

bindcnetwork-programmingport

We have a server application on Windows that fails to bind on the local port (3050) giving error WSAEADDRINUSE - Address already in use.

However, I have checked using SysInternals Utility (TCPView) that no process is listening on that port.

Please suggest what can be the reason behind this and any workaround to overcome this problem.

Thanks in advance.

Best Answer

That error condition will occur under two conditions:

1) Another socket is already bound to that address

2) A socket bound to that address was recently closed.

In the first case, I imagine that the problem is you are binding to that port number twice in the same program.

In the second case, I imagine that a previous run of your program exited or crashed less than 120 seconds before your test. By the time you run TCPView, the 120 seconds have passed.