Skip to content

Commit a27604f

Browse files
committed
add some lines of comment to ChatServer.ino, remove redundant assignment of Client-instance
1 parent 937bce1 commit a27604f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

libraries/Ethernet/examples/ChatServer/ChatServer.ino

+5-3
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,17 @@ void loop() {
6262

6363
boolean newClient = true;
6464
for (byte i=0;i<4;i++) {
65+
//check whether this client refers to the same socket as one of the existing instances:
6566
if (clients[i]==client) {
6667
newClient = false;
6768
break;
6869
}
6970
}
7071

7172
if (newClient) {
73+
//check which of the existing clients can be overridden:
7274
for (byte i=0;i<4;i++) {
73-
if (clients[i]!=client) {
75+
if (!clients[i] && clients[i]!=client) {
7476
clients[i] = client;
7577
break;
7678
}
@@ -89,7 +91,7 @@ void loop() {
8991
if (client.available() > 0) {
9092
// read the bytes incoming from the client:
9193
char thisChar = client.read();
92-
// echo the bytes back to the client:
94+
// echo the bytes back to all other connected clients:
9395
for (byte i=0;i<4;i++) {
9496
if (!clients[i] || (clients[i]==client)) {
9597
continue;
@@ -102,8 +104,8 @@ void loop() {
102104
}
103105
for (byte i=0;i<4;i++) {
104106
if (!(clients[i].connected())) {
107+
// client.stop() invalidates the internal socket-descriptor, so next use of == will allways return false;
105108
clients[i].stop();
106-
clients[i]=EthernetClient();
107109
}
108110
}
109111
}

0 commit comments

Comments
 (0)