Problem with TCP/IP Bind "address already in use"

I have a server app which listens on a port. If the app crashes (with a segmentation fault for example) and I attempt to restart it, I cannot bind() to that same port address again – I receive an “address in use” error.

Apparently, the TCP/IP stack did not clean up resources after the client application crashed. This seems like a serious flaw for a robust OS. I have to believe there is a workaround for this, or perhaps this is a recently introduced bug in 6.3.

Anyone have any information about this?


What is happening to you is normal, this is how TCP/IP works, is not a problem of QNX.

Look at the link:

The links given by johnny can help you. When the server closes due to an error, the server goes to the TIME_WAIT state. In QNX, you should wait about 1 minute to be able to restart the server again. There are several options to change this, but better read the information in the links given by johnny.

I recommend you the book:

Unix Network Programming: The sockets networking api by Richard Stevens.

It has helped me a lot.

I hope it helps.

use setsockopt()!


That is not the fault of QNX. You use setsockopt() and use the SO_REUSEADDR MAcro.

Hope this will solve your problem