libcurl use same user defined port to send periodic request <p>I am working on a project need to send periodic alive message to https server.</p> <p>Because of security issue, we need to use minimal number of ports (blocking unused ports as many as we can).</p> <p>I am using c++ libcurl easy interface to send https request in linux.</p> <p>I have tried to use the same curl handler object (CURL object) and set CURLOPT_LOCALPORT to a port number. The first request is ok. But in the second, libcurl verbose mode said address already in use. However, when I comment out the port set through CURLOPT_LOCALPORT, it works on second connection also, and by setting VERBOSE to 1, I can see "Re-using existing connection" print out, which is missing in version setting up local port. And I check with linux netstat, find out that it is using the same port. I cannot figure out why setting up local port will make it failed.</p> <p>And also, I have tried to close the connection using curl_easy_cleanup, but due to tcp time_wait state, we cannot reuse the port in a while, that's not what I want.</p> <p>Could anyone provide a solution or suggestion to us? Thanks a lot.</p> <p><strong>Edit</strong> My reason using one port is not to keep opening and closing connection too much.</p>