available()


Description

Returns the number of bytes available to read from the server which is connected to.

Syntax

client.available()

Parameters

none

Returns

Returns an int represents the number of bytes available.

Example

#include <SPI.h>
#include <Phpoc.h>

char server_name[] = "www.arduino.cc";
PhpocClient client;

void setup() {
  Serial.begin(9600);
  while(!Serial)
    ;

  Serial.println("PHPoC TCP Client test");

  Phpoc.begin(PF_LOG_SPI | PF_LOG_NET);
  //Phpoc.begin();

  if(client.connect(server_name, 80))
  {
    Serial.println("connected");
    client.write("GET / HTTP/1.0\r\n", 16);
    client.println();
  }
  else
    Serial.println("connection failed");
}

void loop() {
  if(client.available())
  {
    char c = client.read();
    Serial.print(c);
  }

  if(!client.connected())
  {
    Serial.println("disconnected");
    client.stop();
    while(1)
      ;
  }
}