Reference.ClientConnect History

Hide minor edits - Show changes to output

September 13, 2014, at 02:42 PM by Scott Fitzgerald -
Changed lines 26-27 from:
Returns true if the connection succeeds, false if not.
to:
Returns an int (1,-1,-2,-3,-4) indicating connection status :
* SUCCESS 1
* TIMED_OUT -1
* INVALID_SERVER -2
* TRUNCATED -3
* INVALID_RESPONSE -4
November 12, 2012, at 06:38 PM by Scott Fitzgerald -
Added line 11:
''client''.connect()\\
November 09, 2011, at 09:28 PM by Scott Fitzgerald -
Changed lines 37-38 from:
EthernetClient client();
to:
EthernetClient client;
November 09, 2011, at 09:20 PM by Scott Fitzgerald -
Changed lines 31-32 from:
to:
#include <SPI.h>
November 09, 2011, at 09:20 PM by Scott Fitzgerald -
Changed lines 7-8 from:
Connect to the IP address and port specified in the constructor. The return value indicates success or failure.
to:
Connects to a specified IP address and port. The return value indicates success or failure. Also supports DNS lookups when using a domain name.
Changed lines 11-12 from:
''client''.connect()
to:
''client''.connect(ip, port)\\
''client''.connect(URL, port)

Changed lines 17-18 from:
none
to:
ip: the IP address that the client will connect to (array of 4 bytes)

URL: the domain name the client will connect to (string, ex.:"arduino.cc")

port: the port that the client will connect to (int)
Changed lines 36-37 from:
Client client(server, 80);
to:
EthernetClient client();
Changed line 47 from:
if (client.connect()) {
to:
if (client.connect(server, 80)) {
November 01, 2011, at 03:43 PM by Scott Fitzgerald -
Changed line 23 from:
[@
to:
(:source lang=arduino tabwidth=4:)
Changed lines 65-66 from:
@]
to:
(:sourceend:)
September 02, 2008, at 10:39 PM by David A. Mellis -
Added lines 1-66:
[[Ethernet]] : ''Client'' class

!!connect()

!!!!Description

Connect to the IP address and port specified in the constructor. The return value indicates success or failure.

!!!!Syntax

''client''.connect()

!!!!Parameters

none

!!!!Returns

Returns true if the connection succeeds, false if not.

!!!!Example

[@
#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