curl / Mailing Lists / curl-library / Single Mail

curl-library

Re: cURL and custom protocols

From: Daniel Stenberg via curl-library <curl-library_at_cool.haxx.se>
Date: Sun, 27 Jan 2019 23:22:04 +0100 (CET)

On Fri, 25 Jan 2019, Michael Jungnickl via curl-library wrote:

> Does the cURL library support the development of such new protocols?

libcurl does offer "raw" read/write functions, but I can't say it is an
approach we encourage very much. The functions are very basic and often aren't
good enough for implementors to do custom protocols with.

>         res = curl_easy_setopt(curl, CURLOPT_URL, "http://127.0.0.1");
>         res = curl_easy_setopt(curl, CURLOPT_LOCALPORT,    23116);
>
>         // No other initialization, since it's raw data.
>
>         // Some testings, which are wrong I think.
> //        res = curl_easy_setopt(curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP);
> //        res = curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY,     1);

You MUST use CURLOPT_CONNECT_ONLY, but you must also cal curl_easy_perform()
to actually connect. Once that has been successful, you can call:

>         res = curl_easy_send(curl, lpBodyA, nBodyA, &lenSend);
>         res = curl_easy_recv(curl, recData, sizeof(recData), &lenRec);

There's also an example showing how it can be used:

   https://curl.haxx.se/libcurl/c/sendrecv.html

-- 
  / daniel.haxx.se

-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2019-01-27