菜鸟求助,程序kill掉后,再启动,出现bind: Address already in use
程序kill掉之后再启动会出现 bind: Address already in use 的错误
程序bind的端口是8021
netstat -p 显示:
tcp 1364 0 127.0.0.1:8021 127.0.0.1:42119 ESTABLISHED -
tcp 464 0 127.0.0.1:8021 127.0.0.1:48935 ESTABLISHED 1324/qt
tcp 0 0 127.0.0.1:8021 127.0.0.1:48934 CLOSE_WAIT 1324/qt
tcp 30 0 127.0.0.1:8021 127.0.0.1:42118 CLOSE_WAIT -
tcp 0 0 127.0.0.1:42119 127.0.0.1:8021 ESTABLISHED 1324/qt
tcp 0 0 127.0.0.1:48935 127.0.0.1:8021 ESTABLISHED 889/terminal_wdc
tcp 30 0 127.0.0.1:8021 127.0.0.1:42117 CLOSE_WAIT -
tcp 0 0 127.0.0.1:8021 127.0.0.1:48933 CLOSE_WAIT 1324/qt
(其中qt terminal_wdc是作为 tcp客户端连接8021的)
m_addr.sin_addr.s_addr=htonl(INADDR_ANY);int on = 1;int ret = setsockopt( m_nFd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on) );if(bind(m_nFd,(struct sockaddr *)&m_addr,sizeof(m_addr))<0){...}...