Skip to content

Commit c7c1cfd

Browse files
AdvancedChatServer to track up to 8 clients
1 parent 4a64ed3 commit c7c1cfd

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

examples/AdvancedChatServer/AdvancedChatServer.ino

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ IPAddress subnet(255, 255, 0, 0);
3737
// telnet defaults to port 23
3838
EthernetServer server(23);
3939

40-
EthernetClient clients[4];
40+
EthernetClient clients[8];
4141

4242
void setup() {
4343
// You can use Ethernet.init(pin) to configure the CS pin
@@ -83,7 +83,7 @@ void loop() {
8383
if (client) {
8484

8585
boolean newClient = true;
86-
for (byte i=0; i < 4; i++) {
86+
for (byte i=0; i < 8; i++) {
8787
//check whether this client refers to the same socket as one of the existing instances:
8888
if (clients[i] == client) {
8989
newClient = false;
@@ -93,7 +93,7 @@ void loop() {
9393

9494
if (newClient) {
9595
//check which of the existing clients can be overridden:
96-
for (byte i=0; i < 4; i++) {
96+
for (byte i=0; i < 8; i++) {
9797
if (!clients[i] && clients[i] != client) {
9898
clients[i] = client;
9999
// clear out the input buffer:
@@ -111,7 +111,7 @@ void loop() {
111111
// read the bytes incoming from the client:
112112
char thisChar = client.read();
113113
// echo the bytes back to all other connected clients:
114-
for (byte i=0; i < 4; i++) {
114+
for (byte i=0; i < 8; i++) {
115115
if (clients[i] && (clients[i] != client)) {
116116
clients[i].write(thisChar);
117117
}
@@ -120,7 +120,7 @@ void loop() {
120120
Serial.write(thisChar);
121121
}
122122
}
123-
for (byte i=0; i < 4 ; i++) {
123+
for (byte i=0; i < 8 ; i++) {
124124
if (!(clients[i].connected())) {
125125
// client.stop() invalidates the internal socket-descriptor, so next use of == will allways return false;
126126
clients[i].stop();

0 commit comments

Comments
 (0)