I have a situation where my program on a server (windows machine) outputs some strings. I need to send those strings from the server to the client (Linux machine) via HTTP using curl. Once sent I am to receive the data on the client side as string, decode it and perform subsequent actions. I already achieved this functionality using C Sockets using berkely API as I had familiarity with that. But for some reason I am not allowed to use a program of my own using sockets. I poked around and seems CURL can be my solution. However I am very new to curl and cant seem to figure out how to achieve this functionality. On the Client side I found this from the ubuntu forums to be useful may be:
HTML Code:
http://ubuntuforums.org/archive/index.php/t-1435926.html
Code:
#include <curl/curl.h>
#include <cstdio>
#include <string>
std::string buffer;
size_t curl_write( void *ptr, size_t size, size_t nmemb, void *stream)
{
buffer.append((char*)ptr, size*nmemb);
return size*nmemb;
}
int main(int argc, char **argv)
{
CURL *curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, "http://ubuntuforums.org");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_write);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
fwrite( buffer.c_str(), buffer.length(), sizeof(char), stdout);
return 0;
}
I understand that you have to use the write back functions to receive data ? Also on the client side I need to develop a program using curl that whenever the server sends over a string, it should receive it and decode it. Any pointers to tutorials related to the specific problems will be highly appreciated. Or if someone has already tried this I'll highly appreciate any help here. Thanks.
Bookmarks