mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-30 19:52:13 +01:00
Added a notification to the chat client example when the client connects for the first time
This commit is contained in:
parent
b7be90d5ec
commit
0ecc7b031e
@ -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:
|
||||||
@ -51,5 +60,4 @@ void loop() {
|
|||||||
// echo the bytes to the server as well:
|
// echo the bytes to the server as well:
|
||||||
Serial.print(thisChar);
|
Serial.print(thisChar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user