如何明确释放 EADDRINUSE 端口以便再次绑定它?

如何明确释放 EADDRINUSE 端口以便再次绑定它?
$ 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

如何在非REUSEADDR程序之后手动明确释放端口?

我不想每次都等待或更改端口......

答案1

不幸的是,在 Linux 上你什么也做不了(除了修复代码来设置SO_REUSEADDR)。来自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.

相关内容