Added a notification to the chat client example when the client connects for the first time

This commit is contained in:
Tom Igoe 2010-08-10 15:21:00 +00:00
parent b7be90d5ec
commit 0ecc7b031e
1 changed files with 11 additions and 3 deletions

View File

@ -12,7 +12,7 @@
created 18 Dec 2009 created 18 Dec 2009
by David A. Mellis by David A. Mellis
modified 25 July 2010 modified 10 August 2010
by Tom Igoe by Tom Igoe
*/ */
@ -30,6 +30,7 @@ byte subnet[] = { 255, 255, 0, 0 };
// telnet defaults to port 23 // telnet defaults to port 23
Server server(23); Server server(23);
boolean gotAMessage = false; // whether or not you got a message from the client yet
void setup() { void setup() {
// initialize the ethernet device // initialize the ethernet device
@ -43,7 +44,15 @@ void setup() {
void loop() { void loop() {
// wait for a new client: // wait for a new client:
Client client = server.available(); Client client = server.available();
// when the client sends the first byte, say hello:
if (client) { if (client) {
if (!gotAMessage) {
Serial.println("We have a new client");
client.println("Hello, client!");
gotAMessage = true;
}
// read the bytes incoming from the client: // read the bytes incoming from the client:
char thisChar = client.read(); char thisChar = client.read();
// echo the bytes back to the client: // echo the bytes back to the client:
@ -52,4 +61,3 @@ void loop() {
Serial.print(thisChar); Serial.print(thisChar);
} }
} }