From a27604f59ea66be31a52e2c775d9c488aa73f22b Mon Sep 17 00:00:00 2001 From: ntruchsess Date: Wed, 27 Nov 2013 17:49:20 +0100 Subject: [PATCH] add some lines of comment to ChatServer.ino, remove redundant assignment of Client-instance --- libraries/Ethernet/examples/ChatServer/ChatServer.ino | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libraries/Ethernet/examples/ChatServer/ChatServer.ino b/libraries/Ethernet/examples/ChatServer/ChatServer.ino index 281eaea96..14b62dd26 100644 --- a/libraries/Ethernet/examples/ChatServer/ChatServer.ino +++ b/libraries/Ethernet/examples/ChatServer/ChatServer.ino @@ -62,6 +62,7 @@ void loop() { boolean newClient = true; for (byte i=0;i<4;i++) { + //check whether this client refers to the same socket as one of the existing instances: if (clients[i]==client) { newClient = false; break; @@ -69,8 +70,9 @@ void loop() { } if (newClient) { + //check which of the existing clients can be overridden: for (byte i=0;i<4;i++) { - if (clients[i]!=client) { + if (!clients[i] && clients[i]!=client) { clients[i] = client; break; } @@ -89,7 +91,7 @@ void loop() { if (client.available() > 0) { // read the bytes incoming from the client: char thisChar = client.read(); - // echo the bytes back to the client: + // echo the bytes back to all other connected clients: for (byte i=0;i<4;i++) { if (!clients[i] || (clients[i]==client)) { continue; @@ -102,8 +104,8 @@ void loop() { } for (byte i=0;i<4;i++) { if (!(clients[i].connected())) { + // client.stop() invalidates the internal socket-descriptor, so next use of == will allways return false; clients[i].stop(); - clients[i]=EthernetClient(); } } }