Releasing bound ports on process exit

Using SO_REUSEADDR socket option will allow 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))
...         

Leave a Comment