connect()


Description

Connects to a server with specified IP address( or hostname) and port.

Syntax

client.connect(ip_addr, port)
client.connect(hostname, port)

Parameters

ip_addr - the IP address which the client will connect to
port - the port number that the client will connect to
hostname - the hostname that the client will connect to

Returns

1 - on success
0 - on failure

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.println("GET / 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("disconnected");
    client.stop();
    while(1)
      ;
  }
}