创客百科

姿势共享,有节操无门槛参与的创客百科,创客动力之源 \ (^_^) /

用户工具

站点工具


en:arduino:libraries:clientavailable

Ethernet : Client class

available()

Description

Returns the number of bytes available for reading (that is, the amount of data that has been written to the client by the server it is connected to). available() inherits from the Stream utility class.

Syntax

client.available()

Parameters

none

Returns

The number of bytes available.

Example

#include <Ethernet.h>
#include <SPI.h>
 
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10, 0, 0, 177 };
byte server[] = { 64, 233, 187, 99 }; // Google
 
EthernetClient client;
 
void setup()
{
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
 
  delay(1000);
 
  Serial.println("connecting...");
 
  if (client.connect(server, 80)) {
    Serial.println("connected");
    client.println("GET /search?q=arduino HTTP/1.0");
    client.println();
  } else {
    Serial.println("connection failed");
  }
}
 
void loop()
{
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
 
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    for(;;)
      ;
  }
}

Reference Home

本页面的其他翻译:
en/arduino/libraries/clientavailable.txt · 最后更改: 2016/12/25 22:15 (外部编辑)