File tree 4 files changed +9
-11
lines changed
hardware/arduino/cores/arduino
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 {
19
19
virtual void stop () = 0;
20
20
virtual uint8_t connected () = 0;
21
21
virtual operator bool () = 0;
22
+ virtual uint16_t localPort () = 0;
22
23
virtual IPAddress remoteIP () = 0;
23
24
virtual uint16_t remotePort () = 0;
24
25
protected:
Original file line number Diff line number Diff line change @@ -165,13 +165,12 @@ EthernetClient::operator bool() {
165
165
}
166
166
167
167
bool 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);
175
174
}
176
175
177
176
IPAddress EthernetClient::remoteIP () {
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ class EthernetClient : public Client {
25
25
virtual uint8_t connected ();
26
26
virtual operator bool ();
27
27
virtual bool operator ==(const EthernetClient&);
28
+ virtual uint16_t localPort ();
28
29
virtual IPAddress remoteIP ();
29
30
virtual uint16_t remotePort ();
30
31
Original file line number Diff line number Diff line change @@ -72,16 +72,14 @@ void loop() {
72
72
for (byte i=0 ;i<4 ;i++) {
73
73
if (clients[i]!=client) {
74
74
clients[i] = client;
75
- Serial.print (" found slot: " );
76
- Serial.println (i);
77
75
break ;
78
76
}
79
77
}
80
78
81
79
// clead out the input buffer:
82
80
client.flush ();
83
81
Serial.println (" We have a new client" );
84
- client.println (" Hello, client!" );
82
+ client.println (" Hello, client!" );
85
83
client.print (" your IP: " );
86
84
client.println (client.remoteIP ());
87
85
client.print (" your port: " );
@@ -105,7 +103,6 @@ void loop() {
105
103
for (byte i=0 ;i<4 ;i++) {
106
104
if (!(clients[i].connected ())) {
107
105
clients[i].stop ();
108
- ~clients[i];
109
106
clients[i]=EthernetClient ();
110
107
}
111
108
}
You can’t perform that action at this time.
0 commit comments