cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: How to check Server Connection Status using curl_easy_getinfo

From: Praveen Pvs <meetpraveenpvs_at_gmail.com>
Date: Fri, 30 Jan 2015 09:38:08 +0530

On Thu, Jan 29, 2015 at 9:57 PM, Ray Satiro via curl-library <
curl-library_at_cool.haxx.se> wrote:

> On 1/29/2015 4:32 AM, Praveen Pvs wrote:
>
>> Is there way to just check the connection status of server? I need to
>> know the connection status of the server before posting the actual data. If
>> connection with server is available, then post the data to the server
>> otherwise dont post.
>>
>> I have written the following function to check the connection: All the
>> required parameters are set to the curl handler before passing to this
>> function
>>
>
> What do you mean by the connection status? From your client to the server
> or from the server to some backend? If you just want to see if the server
> is up I think a fast way would be HEAD or OPTIONS. Neither is going to work
> in every single case. I don't think there is a generic catch all.

I am trying to check the connection status from my client to the server. I
am sending following HEAD request to determine that.

HEAD /MYCOM/ HTTP/1.1
Host: 10.8.225.10:26030
Accept: */*
Content-Type:text/xml

>
> I am testing this function with various servers to which i need to post
>> the data. one server was returning CURLE_OK for curl_easy_perform function
>> and CURLINFO_RESPONSE_CODE as 200 (which i considered as success), but one
>> more server was returning 22(CURLE_HTTP_RETURNED_ERROR) for
>> curl_easy_perform function and CURLINFO_RESPONSE_CODE as 404.
>>
>
> So for connection status currently you are retrieving target page on
> servers and get a 200? And in the case of one server you get 404 and it's
> not. It sounds like your program is doing what you intended, no?

When I sent above HEAD request to two servers. One of them returned
CURLINFO_RESPONSE_CODE as 200 and another one as 404. But both the servers
are up and running. So i am not sure how to determine that connection to
server is available.

>
>
> I tried to use CURLINFO_HTTP_CONNECTCODE instead of
>> CURLINFO_RESPONSE_CODE with the second server, i have received 0 for the
>> CURLINFO_HTTP_CONNECTCODE. I am not sure whether this value can be
>> considered as success.
>>
>
> CURLINFO_HTTP_CONNECTCODE is to get the proxy's response if you are
> tunneling via CONNECT which would happen with an https connection or if you
> have enabled CURLOPT_HTTPPROXYTUNNEL. It is not for a backend server proxy
> but a proxy between your client and the server, ie client <-> proxy <->
> server

Thank you for your explanation.

>
>
> Could you please help me to make it generic to test the connection status
>> of the server?
>>
>
> I doubt it but someone may come up with something if you give more detail.
>
> Problem statement: My client program should able to determine whether the
connection is available to the server before posting the actual data.
client would like to know that it is able to connect to server before
posting the actual data.

> -------------------------------------------------------------------
> List admin: http://cool.haxx.se/list/listinfo/curl-library
> Etiquette: http://curl.haxx.se/mail/etiquette.html

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2015-01-30