How to explicitly free EADDRINUSE port for binding it again?

0

$ testOnDemandRTSPServer
... Play this stream using the URL "rtsp://192.168.90.2:8554 ...
^C
$ testOnDemandRTSPServer
Failed to create RTSP server: bind() error (port number: 8554): Address already in use

How to manually explicitly free up the port after a non-REUSEADDR program?

I don't want to wait or change port every time...

Vi.

Posted 2013-04-24T11:53:11.077

Reputation: 13 705

Answers

0

Unfortunately, on Linux there's nothing you can do (other than fixing the code to set SO_REUSEADDR). From man 7 socket:

Linux will only allow port reuse with the SO_REUSEADDR option when this
option was set both in the previous program that performed a bind(2) to
the port and in the program that wants to reuse the port. This differs
from some implementations (e.g., FreeBSD) where only the later program
needs to set the SO_REUSEADDR option. Typically this difference is invisible,
since, for example, a server program is designed to always set this option.

Gabe

Posted 2013-04-24T11:53:11.077

Reputation: 1 837

2Is it just me who annoyed by Address already in use message during development? Maybe somebody hacked up a kernel module that just flushes all TIME_WAIT sockets? – Vi. – 2013-04-26T11:01:06.097