Example of the SO_REUSEADDR Option
2009-04-21 13:29
543 查看
quoted fromhttp://www.docs.hp.com/en/B2355-90136/ch03s01.htmlThis option is AF_INET socket-specific.SO_REUSEADDRenables you to restart a daemon which was killed or terminated.This option modifies the rules used by bind to validate local addresses, but it does not violate the uniqueness requirements of an association. SO_REUSEADDR modifies the bind rules only when a wildcard Internet Protocol (IP) address is used in combination with a particular protocol port. The host still checks at connection time to be sure any other sockets with the same local address and local port do not have the same remote address and remote port. Connectfails if the uniqueness requirement is violated.
Network Daemon Server Listening at Port 2000When the network daemon accepts a connection request, the accepted socket will bindto port 2000 and to the address where the daemon is running (e.g. 192.6.250.100). If you executed netstat an, the output would resemble:
New Connection Established, Daemon Server Still ListeningHere the network daemon has established a connection to the client (192.6.250.101.4000) with a new server socket. The original network daemon server continues to listen for more connection requests.If the listening network daemon process is killed, attempts to restart the daemon fail if SO_REUSEADDR is not set. The restart fails because the daemon attempts to bind to port 2000 and a wildcard IP address (e.g. *.2000). The wildcard address matches the address of the established connection (192.6.250.100), so the bindaborts to avoid duplicate socket naming.When SO_REUSEADDRis set, bindignores the wildcard match, so the network daemon can be restarted. An example usage of this option is:
Example of the SO_REUSEADDR Option
A network daemon server is listening on a specific port: port 2000. If you executed netstat an, part of the output would resemble:Active connections (including servers)Proto Recv-Q Send-Q Local Address Foreign Address (state)tcp 0 0 *.2000 *.* LISTEN |
Active connections (including servers)Proto Recv-Q Send-Q Local Address Foreign Address (state)tcp 0 0 192.6.250.100.2000 192.6.250.101.4000 ESTABLISHEDtcp 0 0 *.2000 *.* LISTEN |
int optval = 1;setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &optval,sizeof(optval));bind (s, &sin, sizeof(sin)); |
相关文章推荐
- ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot exe
- ServerSocket选项的基本解析:SO_TIMEOUT选项、SO_REUSEADDR选项、SO_RCVBUF选项
- MYSQL 5.7报错 Error Code: 1290. The MySQL server is running with the --secure-file-priv option so it..
- ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it ...statemet
- MySQL用into outfile导出出错The MySQL server is running with the --secure-file-priv option so it cannot ex
- Example uses of the Linux Command ftp
- get the text value of a selected option.
- Warning: Skipping the data of table mysql.event. Specify the --events option explicitly
- ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot exec
- Simple example of using the Java Native Interface(JNI)
- Oracle: Benefits and consequences of the NOLOGGING option
- ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot exec
- ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot exec
- 端口复用 -- socket编程:SO_REUSEADDR例解
- Example uses of the Linux Command ftp
- MySQL报错:The MySQL server is running with the --skip-grant-tables option so it cannot execute this st
- The example of Using Executors
- -- Warning: Skipping the data of table mysql.event. Specify the --events option explicitly.
- A simple Example of data processing from Excel as the datasource
- The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement