Skip to content

Commit a3f853c

Browse files
committed
Added a notification to the chat client example when the client connects for the first time
1 parent 43eed7d commit a3f853c

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

examples/ChatServer/ChatServer.pde

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
created 18 Dec 2009
1414
by David A. Mellis
15-
modified 25 July 2010
15+
modified 10 August 2010
1616
by Tom Igoe
1717
1818
*/
@@ -30,6 +30,7 @@ byte subnet[] = { 255, 255, 0, 0 };
3030

3131
// telnet defaults to port 23
3232
Server server(23);
33+
boolean gotAMessage = false; // whether or not you got a message from the client yet
3334

3435
void setup() {
3536
// initialize the ethernet device
@@ -43,13 +44,20 @@ void setup() {
4344
void loop() {
4445
// wait for a new client:
4546
Client client = server.available();
47+
48+
// when the client sends the first byte, say hello:
4649
if (client) {
50+
if (!gotAMessage) {
51+
Serial.println("We have a new client");
52+
client.println("Hello, client!");
53+
gotAMessage = true;
54+
}
55+
4756
// read the bytes incoming from the client:
4857
char thisChar = client.read();
4958
// echo the bytes back to the client:
5059
server.write(thisChar);
5160
// echo the bytes to the server as well:
5261
Serial.print(thisChar);
5362
}
54-
}
55-
63+
}

0 commit comments

Comments
 (0)