1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-17 22:23:10 +03:00

Merge branch 'master' of github.com:arduino/Arduino

This commit is contained in:
Cristian Maglie
2013-12-13 18:26:44 +01:00
4 changed files with 7 additions and 36 deletions

View File

@ -19,9 +19,6 @@ public:
virtual void stop() = 0; virtual void stop() = 0;
virtual uint8_t connected() = 0; virtual uint8_t connected() = 0;
virtual operator bool() = 0; virtual operator bool() = 0;
virtual uint16_t localPort() = 0;
virtual IPAddress remoteIP() = 0;
virtual uint16_t remotePort() = 0;
protected: protected:
uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); }; uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); };
}; };

View File

@ -167,20 +167,3 @@ EthernetClient::operator bool() {
bool EthernetClient::operator==(const EthernetClient& rhs) { bool EthernetClient::operator==(const EthernetClient& rhs) {
return _sock == rhs._sock && _sock != MAX_SOCK_NUM && rhs._sock != MAX_SOCK_NUM; return _sock == rhs._sock && _sock != MAX_SOCK_NUM && rhs._sock != MAX_SOCK_NUM;
} }
uint16_t EthernetClient::localPort() {
if (_sock == MAX_SOCK_NUM) return 0;
return W5100.readSnPORT(_sock);
}
IPAddress EthernetClient::remoteIP() {
if (_sock == MAX_SOCK_NUM) return IPAddress(0,0,0,0);
uint32_t _destaddress;
W5100.readSnDIPR(_sock,(uint8_t*) &_destaddress);
return IPAddress(_destaddress);
}
uint16_t EthernetClient::remotePort() {
if (_sock == MAX_SOCK_NUM) return 0;
return W5100.readSnDPORT(_sock);
}

View File

@ -25,9 +25,7 @@ public:
virtual uint8_t connected(); virtual uint8_t connected();
virtual operator bool(); virtual operator bool();
virtual bool operator==(const EthernetClient&); virtual bool operator==(const EthernetClient&);
virtual uint16_t localPort(); virtual bool operator!=(const EthernetClient& rhs) { return !this->operator==(rhs); };
virtual IPAddress remoteIP();
virtual uint16_t remotePort();
friend class EthernetServer; friend class EthernetServer;

View File

@ -75,22 +75,15 @@ void loop() {
for (byte i=0;i<4;i++) { for (byte i=0;i<4;i++) {
if (!clients[i] && clients[i]!=client) { if (!clients[i] && clients[i]!=client) {
clients[i] = client; clients[i] = client;
break;
}
}
// clead out the input buffer: // clead out the input buffer:
client.flush(); client.flush();
Serial.println("We have a new client"); Serial.println("We have a new client");
client.println("Hello, client!"); client.print("Hello, client number: ");
client.print("my IP: "); client.print(i);
client.println(Ethernet.localIP()); client.println();
client.print("my port: "); break;
client.println(client.localPort()); }
client.print("your IP: "); }
client.println(client.remoteIP());
client.print("your port: ");
client.println(client.remotePort());
} }
if (client.available() > 0) { if (client.available() > 0) {