File tree 1 file changed +5
-3
lines changed
libraries/Ethernet/examples/ChatServer
1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -62,15 +62,17 @@ void loop() {
62
62
63
63
boolean newClient = true ;
64
64
for (byte i=0 ;i<4 ;i++) {
65
+ // check whether this client refers to the same socket as one of the existing instances:
65
66
if (clients[i]==client) {
66
67
newClient = false ;
67
68
break ;
68
69
}
69
70
}
70
71
71
72
if (newClient) {
73
+ // check which of the existing clients can be overridden:
72
74
for (byte i=0 ;i<4 ;i++) {
73
- if (clients[i]!=client) {
75
+ if (!clients[i] && clients[i]!=client) {
74
76
clients[i] = client;
75
77
break ;
76
78
}
@@ -89,7 +91,7 @@ void loop() {
89
91
if (client.available () > 0 ) {
90
92
// read the bytes incoming from the client:
91
93
char thisChar = client.read ();
92
- // echo the bytes back to the client :
94
+ // echo the bytes back to all other connected clients :
93
95
for (byte i=0 ;i<4 ;i++) {
94
96
if (!clients[i] || (clients[i]==client)) {
95
97
continue ;
@@ -102,8 +104,8 @@ void loop() {
102
104
}
103
105
for (byte i=0 ;i<4 ;i++) {
104
106
if (!(clients[i].connected ())) {
107
+ // client.stop() invalidates the internal socket-descriptor, so next use of == will allways return false;
105
108
clients[i].stop ();
106
- clients[i]=EthernetClient ();
107
109
}
108
110
}
109
111
}
You can’t perform that action at this time.
0 commit comments