Reference.ClientAvailable History

Hide minor edits - Show changes to markup

November 09, 2011, at 09:27 PM by Scott Fitzgerald -
Changed lines 33-34 from:

EthernetClient client();

to:

EthernetClient client;

November 09, 2011, at 09:25 PM by Scott Fitzgerald -
Changed lines 27-28 from:
to:
  1. include <SPI.h>
Changed lines 33-34 from:

Client client(server, 80);

to:

EthernetClient client();

Changed line 44 from:
  if (client.connect()) {
to:
  if (client.connect(server, 80)) {
November 04, 2011, at 06:22 PM by Scott Fitzgerald -
Added lines 9-10:

available() inherits from the Stream utility class.

Added lines 69-72:

See also

November 01, 2011, at 03:45 PM by Scott Fitzgerald -
Added lines 21-22:

Example

November 01, 2011, at 03:45 PM by Scott Fitzgerald -
Changed line 21 from:

[@

to:
Changed lines 63-64 from:

@]

to:
September 02, 2008, at 10:39 PM by David A. Mellis -
Added lines 1-64:

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).

Syntax

client.available()

Parameters

none

Returns

The number of bytes available.

#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10, 0, 0, 177 };
byte server[] = { 64, 233, 187, 99 }; // Google

Client client(server, 80);

void setup()
{
  Ethernet.begin(mac, ip);
  Serial.begin(9600);

  delay(1000);

  Serial.println("connecting...");

  if (client.connect()) {
    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(;;)
      ;
  }
}

Share