curl-library
Re: Use of multi interface of libcurl
Date: Thu, 30 Dec 2010 10:36:56 -0500
On Thu, Dec 30, 2010 at 10:26 AM, Daniel Stenberg <daniel_at_haxx.se> wrote:
> On Thu, 30 Dec 2010, amit paliwal wrote:
>
> Please refer to below sample code as it is not working for me, please help
>> me find problem in it. I posted it in another thread also but not gettign
>> any response and it is very imp for me:
>>
>
> You posted that less than 24 hours ago. If you want faster answers than so,
> buy support from someone.
Reply: that is right, my apologies for that, I always get timely response
from you guys and thanks a lot for that.
>
>
> curl_easy_setopt( ctx , CURLOPT_URL, "http://localhost:4433" ) ;
>> curl_easy_setopt( ctx , CURLOPT_INTERFACE, "127.0.0.1" ) ;
>> curl_easy_setopt( ctx , CURLOPT_LOCALPORT, 4434 );
>>
>
> Can you please explain to us the logic and reason for these two latter
> options in combination with that URL?
I am running Server and Client on same machine and they are communicating on
loopback. As per the document CURLOPT_URL is mandatory for
curl_easy_perform, I have mentioned it and have given localhost port 4433,
where server is listening.
Client is binded on port 4434, yesterday Daniel mentioned that
CURLOPT_INTERFACE is used for client to bind on local port, so my client is
binded on port 4434.
>
>
> curl_easy_setopt(ctx, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
>>
>
> HTTP 1.1 is default.
>
> size_t write_data( void *buffer, size_t size, size_t nmemb, void *userp )
>> {
>> int segsize = size * nmemb;
>>
>> CURL *ctx = (CURL*)userp;
>> printf("\nCurl object address is:%p",ctx);
>> CURLcode ret;
>>
>> curl_easy_setopt( ctx1 , CURLOPT_READDATA ,ctx);
>> curl_easy_setopt( ctx1 , CURLOPT_READFUNCTION , readcb );
>> curl_easy_setopt(ctx1, CURLOPT_CUSTOMREQUEST, "GET") ;
>> *int ret = curl_easy_perform(ctx1);*
>>
>
> You can't call curl_easy_perform() from within the write callback on the
> same handle. That will either not work or cause chaos.
>
> If you really want to do something from within the write callback then you
> need to understand what you're doing (the recursive nature and the fact that
> the first response will be "paused" there until the second request is
> completed) and you need to it with another curl handle.
>
> That sounds logical, I guessed it and thanks for the clear response. In
this case how will I send second GET request, if I am not wrong then I need
to call curl_easy_perform() every time I need to send a GET request, is it
right??? By providing readcb, will I be able to send GET with my custom
data???
> --
>
> / daniel.haxx.se
>
> -------------------------------------------------------------------
> 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 2010-12-30