且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ServerSocket中setReuseAddress的目的是什么?

更新时间:2022-06-12 05:18:09

这个解释来自涉及一些的TCP机制低级套接字属性和协议,基本上有一个名为SO_REUSEADDR的选项,您在创建套接字时定义,使用方法 setReuseAddress()启用或禁用此行为。

This explanation is coming from TCP mechanism involving some low level socket properties and protocols, basically there is an option called SO_REUSEADDR that you define when you are creating the socket, using the method setReuseAddress() enable or disable this behavior.

目前的解释非常明确这里,看看那里。另外 API 有很好的解释

The current explanation is very well defined here, take a look there. Also API have very good explanation

只需将其作为可使用该方法修改的配置参数。

Just take as a configuration parameter that can be modified using that method.


在使用
bind(SocketAddress)绑定套接字之前启用SO_REUSEADDR允许套接字绑定,即使
之前的连接处于超时状态。

Enabling SO_REUSEADDR prior to binding the socket using bind(SocketAddress) allows the socket to be bound even though a previous connection is in a timeout state.