File tree Expand file tree Collapse file tree 4 files changed +9
-11
lines changed
hardware/arduino/cores/arduino Expand file tree Collapse file tree 4 files changed +9
-11
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ class Client : public Stream {
1919 virtual void stop () = 0;
2020 virtual uint8_t connected () = 0;
2121 virtual operator bool () = 0;
22+ virtual uint16_t localPort () = 0;
2223 virtual IPAddress remoteIP () = 0;
2324 virtual uint16_t remotePort () = 0;
2425protected:
Original file line number Diff line number Diff line change @@ -165,13 +165,12 @@ EthernetClient::operator bool() {
165165}
166166
167167bool EthernetClient::operator ==(const EthernetClient& rhs) {
168- if (_sock == MAX_SOCK_NUM || rhs._sock == MAX_SOCK_NUM) return false ;
169- if (W5100.readSnDPORT (_sock)!=W5100.readSnDPORT (rhs._sock )) return false ;
170- uint32_t a1;
171- uint32_t a2;
172- W5100.readSnDIPR (_sock,(uint8_t *) &a1);
173- W5100.readSnDIPR (rhs._sock ,(uint8_t *) &a2);
174- return a1==a2;
168+ return _sock == rhs._sock && _sock != MAX_SOCK_NUM && rhs._sock != MAX_SOCK_NUM;
169+ }
170+
171+ uint16_t EthernetClient::localPort () {
172+ if (_sock == MAX_SOCK_NUM) return 0 ;
173+ return W5100.readSnPORT (_sock);
175174}
176175
177176IPAddress EthernetClient::remoteIP () {
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ class EthernetClient : public Client {
2525 virtual uint8_t connected ();
2626 virtual operator bool ();
2727 virtual bool operator ==(const EthernetClient&);
28+ virtual uint16_t localPort ();
2829 virtual IPAddress remoteIP ();
2930 virtual uint16_t remotePort ();
3031
Original file line number Diff line number Diff line change @@ -72,16 +72,14 @@ void loop() {
7272 for (byte i=0 ;i<4 ;i++) {
7373 if (clients[i]!=client) {
7474 clients[i] = client;
75- Serial.print (" found slot: " );
76- Serial.println (i);
7775 break ;
7876 }
7977 }
8078
8179 // clead out the input buffer:
8280 client.flush ();
8381 Serial.println (" We have a new client" );
84- client.println (" Hello, client!" );
82+ client.println (" Hello, client!" );
8583 client.print (" your IP: " );
8684 client.println (client.remoteIP ());
8785 client.print (" your port: " );
@@ -105,7 +103,6 @@ void loop() {
105103 for (byte i=0 ;i<4 ;i++) {
106104 if (!(clients[i].connected ())) {
107105 clients[i].stop ();
108- ~clients[i];
109106 clients[i]=EthernetClient ();
110107 }
111108 }
You can’t perform that action at this time.
0 commit comments