[ACCEPTED]-Releasing bound ports on process exit-sockets
Accepted answer
Using SO_REUSEADDR socket option will allow 1 you to re-start the program without delay.
int iSetOption = 1;
...
sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
setsockopt(_sockfd, SOL_SOCKET, SO_REUSEADDR, (char*)&iSetOption,
sizeof(iSetOption))
...
TCP/IP stack keeps port busy for sometime 5 even after close()
- socket will stay in TIME_WAIT
and TIME_WAIT2
state.
If 4 I'm not mistaken, usually it takes 2 minutes 3 so if you need to use the same port immediately 2 set SO_REUSEADDR
option on your socket before binding, just 1 like Ivo Bosticky suggested.
Not exactly an answer to your question, but 4 for completeness:
On Windows you can set 3 the TcpTimedWaitDelay registry value to set the timeout 2 for releasing closed TCP connections to 1 as low as 30 seconds.
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.