cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: c++ libcurl: telnet

From: Julius Morales Reolizo <myst_frozenshadow_at_yahoo.com>
Date: Tue, 27 May 2008 22:57:59 -0700 (PDT)

Gary Maxwell wrote:
How are you displaying the data received from the server (wunderground)?
If you are writing the data directly to a console window, the data is
usually buffered until (1) a newline is found in the data, or (2) a read
request is made to the window (implied flush), or (3) the contents of
the buffer are flushed.

This would explain why you are not seeing the last prompt received by
the server, since there is no newline present, and I assume the data you
are sending back to the server does not originate from your console
window.

Feel free to post your application code, then we might be able to offer
better assistance.

-Gary

//#include <string>
#include <iostream>
#include "curl/curl.h"

using namespace std;

static char errorBuffer[CURL_ERROR_SIZE];

int main(int argc, char* argv[]) {
  if (argc > 1) {
    string url(argv[1]);
        
    CURL *curl;
    CURLcode result;
    
    curl = curl_easy_init();

    if (curl) {
      curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer);
      curl_easy_setopt(curl, CURLOPT_FAILONERROR,1);
      curl_easy_setopt(curl, CURLOPT_URL, "telnet://rainmaker.wunderground.com/");
      curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);

      result = curl_easy_perform(curl);

      curl_easy_cleanup(curl);

      if (result == CURLE_OK) {
          while(cin) {
              string input_line;
            getline(cin, input_line);
            cout << input_line << endl;
          }
      } else {
        cout << "Error: [" << result << "] - " << errorBuffer;
        exit(-1);
      }
    }
  }
}

      
Received on 2008-05-28