File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed
libraries/Ethernet/examples/ChatServer Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments