write()


Description

Writes data to the server the client is connected to.
This data is sent as a byte or series of bytes.

Syntax

client.write(val)
client.write(buf, len)

Parameters

val - a value to send as a single byte (byte of char)
buf - an array to send as a series of bytes (byte or char)
len - the length of the buffer

Returns

Returns an int represents the number of bytes written.

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)
      ;
  }
}