当前位置: 首页>>代码示例>>C++>>正文


C++ HTTPClient::connected方法代码示例

本文整理汇总了C++中HTTPClient::connected方法的典型用法代码示例。如果您正苦于以下问题:C++ HTTPClient::connected方法的具体用法?C++ HTTPClient::connected怎么用?C++ HTTPClient::connected使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HTTPClient的用法示例。


在下文中一共展示了HTTPClient::connected方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: closeStream

int
HTTPClient::clientWrite(char byte, FILE* stream)
{
  if (stream == NULL)
    {
      return EOF;
    }
  http_stream_udata* udata = (http_stream_udata*) fdev_get_udata(stream);
  HTTPClient* client = udata->client;
  if (client->connected() == 0)
    {
      closeStream(stream);
      return EOF;
    }
  if (udata->encode == 0)
    {
      client->write(byte);
      if (client->debugCommunication)
        {
          Serial.print(byte);
        }
    }
  else
    {
      if (URI_ALLOWED(byte) || ((URI_RESERVED(byte) && (udata->encode
          & URI_ENCODE_RESERVED) == 0)))
        {
          client->write(byte);
          if (client->debugCommunication)
            {
              Serial.print(byte);
            }
        }
      else
        {
          char encoded[4] =
            { 0, 0, 0 };
          sprintf(encoded, "%%%2x", byte);
          // Write only the first three bytes, not the trailing null
          for (char i = 0; i < 3; i++)
            {
              client->write(encoded[i]);
              if (client->debugCommunication)
                {
                  Serial.print(encoded[i]);
                }
            }
        }
    }
  return 0;
}
开发者ID:hex705,项目名称:avviso,代码行数:51,代码来源:HTTPClient.cpp

示例2: if

int
HTTPClient::clientRead(FILE* stream)
{
  if (stream == NULL)
    {
      return EOF;
    }
  http_stream_udata* udata = (http_stream_udata*) fdev_get_udata(stream);
  HTTPClient* client = udata->client;
  if (!client->connected())
    {
      return EOF;
    }
  //block until we got a byte
  while (client->available() == 0)
    {
      if (client->connected() == 0)
        {
          return EOF;
        }
    };
  int result = client->read();
  if (result == EOF)
    {
      return EOF;
    }
  if (client->debugCommunication)
    {
      Serial.print((byte) result);
    }
  //as long as we do not read encoded or it is no % everything is ok
  if (udata->encode == 0 || result != '%')
    {
      return result;
    }
  else
    {
      //block until we got the needed bytes
      while (client->available() >= 2)
        {
          if (client->connected() == 0)
            {
              return EOF;
            }
        };
      char return_value = 0;
      for (char i = 0; i < 2; i++)
        {
          result = client->read();
          if (result == EOF)
            {
              return EOF;
            }
          else if (result >= 'A' && result <= 'Z')
            {
              return_value += (1 - i) * 16 * (result - 'A');
            }
          else if (result >= 'a' && result <= 'z')
            {
              return_value += (1 - i) * 16 * (result - 'a');
            }
          else if (result >= '0' && result <= '9')
            {
              return_value += (1 - i) * 16 * (result - '0');
            }
        }
      return return_value;
    }
}
开发者ID:hex705,项目名称:avviso,代码行数:69,代码来源:HTTPClient.cpp

示例3: uploadFile

int uploadFile(const char* _filename, const char* _fileurl) { // upload new file to fs by downloading from a remote server, rather than reflash the entire spiffs
  int ret = false;
  HTTPClient http;
  //const char* fileUrl = "http://mypi3/iot/index.html";
  //const char* fileName = "/test2.html";

  if (hasSerial) Serial.printf("url %s\n", _fileurl);
  if (hasSerial) Serial.printf("file %s\n", _filename);

  http.begin(_fileurl); // init http client

  // start connection and send HTTP header
  int httpCode = http.GET();

  // httpCode will be negative on error
  if(httpCode > 0) {
    // HTTP header has been send and Server response header has been handled
    // file found at server
    if(httpCode == HTTP_CODE_OK) {
      if (hasSerial) Serial.printf("HTTP client http status %d\n", httpCode);

      // get lenght of document (is -1 when Server sends no Content-Length header)
      int len = http.getSize();
      int paysize = len;

      if (hasSerial) Serial.printf("HTTP content size %d bytes\n", paysize);

      // create buffer for read
      uint8_t buff[128] = { 0 };

      // get tcp stream
      WiFiClient * stream = http.getStreamPtr();

      // create or recreate file on spiffs
      File configFile = SPIFFS.open(_filename, "w");
      if (!configFile) {
        if (hasSerial) Serial.printf("Failed to open %s for write.\n",_filename);
        return ret;
      }
      if (hasSerial) Serial.println("File open, write start.");

      // read all data from server
      while(http.connected() && (len > 0 || len == -1)) {
        // get available data size
        size_t size = stream->available();

        if (size) {
              // read up to 128 byte
              int c = stream->readBytes(buff, ((size > sizeof(buff)) ? sizeof(buff) : size));

              // write it to Serial
              configFile.write(buff, c);

              if(len > 0) {
                  len -= c;
              }
        }
      } // EoF or http connection closed
      configFile.close();
      http.end();
      if (hasSerial) Serial.println("File closed, write complete.");
      return paysize;
    } else {
      if (hasSerial) Serial.printf("HTTP client http error %d\n", httpCode);
      return httpCode;
    }
  } else {
    if (hasSerial) Serial.printf("HTTP client http error %d\n", httpCode);
    return httpCode;
  }

  return 0;
}
开发者ID:gordonthree,项目名称:multiswitch,代码行数:73,代码来源:multiswitch.cpp


注:本文中的HTTPClient::connected方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。