Skip to content

Commit a465571

Browse files
committed
small changes to AdvancedChatserver.ino plus add operator!=
1 parent 1d64e99 commit a465571

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

UIPClient.h

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class UIPClient : public Client {
6464
uint8_t connected();
6565
operator bool();
6666
virtual bool operator==(const EthernetClient&);
67+
virtual bool operator!=(const EthernetClient& rhs) { return !this->operator==(rhs); };
6768
virtual uint16_t localPort();
6869
virtual IPAddress remoteIP();
6970
virtual uint16_t remotePort();

examples/AdvancedChatServer/AdvancedChatServer.ino

+16-16
Original file line numberDiff line numberDiff line change
@@ -69,33 +69,33 @@ void loop() {
6969
for (byte i=0;i<4;i++) {
7070
if (!clients[i] && clients[i]!=client) {
7171
clients[i] = client;
72+
// clead out the input buffer:
73+
client.flush();
74+
// clead out the input buffer:
75+
client.flush();
76+
Serial.println("We have a new client");
77+
client.println("Hello, client!");
78+
client.print("my IP: ");
79+
client.println(Ethernet.localIP());
80+
client.print("my port: ");
81+
client.println(client.localPort());
82+
client.print("your IP: ");
83+
client.println(client.remoteIP());
84+
client.print("your port: ");
85+
client.println(client.remotePort());
7286
break;
7387
}
7488
}
75-
76-
// clead out the input buffer:
77-
client.flush();
78-
Serial.println("We have a new client");
79-
client.println("Hello, client!");
80-
client.print("my IP: ");
81-
client.println(Ethernet.localIP());
82-
client.print("my port: ");
83-
client.println(client.localPort());
84-
client.print("your IP: ");
85-
client.println(client.remoteIP());
86-
client.print("your port: ");
87-
client.println(client.remotePort());
8889
}
8990

9091
if (client.available() > 0) {
9192
// read the bytes incoming from the client:
9293
char thisChar = client.read();
9394
// echo the bytes back to all other connected clients:
9495
for (byte i=0;i<4;i++) {
95-
if (!clients[i] || (clients[i]==client)) {
96-
continue;
96+
if (clients[i] && clients[i]!=client) {
97+
clients[i].write(thisChar);
9798
}
98-
clients[i].write(thisChar);
9999
}
100100
// echo the bytes to the server as well:
101101
Serial.write(thisChar);

0 commit comments

Comments
 (0)