Reference.ClientConnected History

Hide minor edits - Show changes to output

October 31, 2012, at 10:59 AM by Roberto Guido - minor correction in example, to evidence usage of connected()
Added lines 37-38:
client.connect(server, 80);
delay(1000);
Deleted lines 39-40:
delay(1000);
Changed line 42 from:
if (client.connect(server, 80)) {
to:
if (client.connected()) {
November 09, 2011, at 09:27 PM by Scott Fitzgerald -
Changed lines 31-32 from:
EthernetClient client();
to:
EthernetClient client;
November 09, 2011, at 09:24 PM by Scott Fitzgerald -
Changed lines 25-26 from:
to:
#include <SPI.h>
Changed lines 31-32 from:
Client client(server, 80);
to:
EthernetClient client();
Changed line 42 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:)
Changed lines 65-66 from:
@]
to:
(:sourceend:)
February 10, 2009, at 10:36 AM by David A. Mellis -
Added lines 1-66:
[[Ethernet]] : ''Client'' class

!!connected()

!!!!Description

Whether or not the client is connected. Note that a client is considered connected if the connection has been closed but there is still unread data.

!!!!Syntax

''client''.connected()

!!!!Parameters

none

!!!!Returns

Returns true if the client is connected, 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