cURL / Mailing Lists / curl-library / Single Mail

curl-library

Asynchronous communication using libcurl

From: Kowsik Tulabandula <kowsik.tulabandula_at_gmail.com>
Date: Tue, 2 Jul 2013 02:51:45 +0530

Hi,

I am new to HTTP, HTTPS and libcurl.

My requirement is as below:

   1. A client program should handle communication with more than 3000
   servers using XML/HTTPS.
   2. Communication involves client program sending requests and waiting
   for response to the request. And also, the server can send asynchronously
   events to client program. I am looking for a asynchronous approach
   considering the high scale numbers.

I saw a few sample programs, and identified three approaches.

*Approach 1: (Using curl_easy_handle)*

       One using curl easy handle and do synchronous communication with
server. This will require one dedicated thread to send request and wait for
curl_easy_perform to complete i.e, until response is received. Also, using
curl_easy_perform, client program cant subscribe for events from servers. I
wrote a sample program which is able to send xml requests over https and
receive response. Since easy handle only provides synchronous
communication, i think it is better not to use this approach.

*Approach 2: (Using curl_easy_recv and curl_easy_send)*

I tried using curl_easy_send and curl_easy_recv using curl_connect_only
option. When i tried a sample program, the server side apache is failing
the request saying "request failed: error reading the headers". And the
client program is not receiving any response (not even failure) and select
timeouts.

The request i am passing to curl_easy_send is (I am assuming that we have
to send headers also when we send request using curl_easy_send):

POST /nuova HTTP/1.1
Host: 10.105.214.136
Accept: */*
Content-Type: text/xml
Content-Length: 46
<login inName="admin" inPassword="xxxxxxxx"/>

But if i send the same using curl binary or POST binary i am able to get
response:

cat login.xml.old
<login inName="admin" inPassword="xxxxxxxx"/>

curl --insecure -X POST -d @login.xml.old https://10.105.214.136/auth
 <login response="yes" outCookie="yyyyyyy"> </login>

I just modified the sendrecv.c example available in curl docs. Am i passing
the headers wrong or can't we use curl_easy_send or curl_easy_recv for
these kind of requirements?

*Approach 3: (Using curl_multi_handle)*
*
*
Other approach i haven't tried is using multi handle to achieve
asynchronous implementation. Is there any sample example i can refer to ?

*Asynchronous Event Notification:*

Also my client program should be listening to events sent by servers, i
want to know if the following works or not?

open a curl connection using Approach 2 or Approach 3 and send a request to
server. On server, apache receives the connection request and will get hold
of the socket used for https connection and will keep writing the events on
this socket while the client program will get socket from handle and will
be doing poll/select to listen on event notifications followed by receive.

Is there any better approach for subscribing to event notifications using
libcurl ?

Also, if you know of any better approaches please guide me. Thanks in
Advance.

Please let me know if more information is needed. I can copy the sample
program i used.

Regards,
Kowsik

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