diff --git a/libraries/ESP8266WiFi/src/WiFiServer.cpp b/libraries/ESP8266WiFi/src/WiFiServer.cpp index d9d47657df..494bf61dd5 100644 --- a/libraries/ESP8266WiFi/src/WiFiServer.cpp +++ b/libraries/ESP8266WiFi/src/WiFiServer.cpp @@ -83,6 +83,7 @@ void WiFiServer::begin(uint16_t port) { return; } _pcb = listen_pcb; + _port = _pcb->local_port; tcp_accept(listen_pcb, &WiFiServer::_s_accept); tcp_arg(listen_pcb, (void*) this); } @@ -126,6 +127,10 @@ uint8_t WiFiServer::status() { return _pcb->state; } +uint16_t WiFiServer::port() const { + return _port; +} + void WiFiServer::close() { if (!_pcb) { return; diff --git a/libraries/ESP8266WiFi/src/WiFiServer.h b/libraries/ESP8266WiFi/src/WiFiServer.h index ec0cea17d6..7a4a3246d3 100644 --- a/libraries/ESP8266WiFi/src/WiFiServer.h +++ b/libraries/ESP8266WiFi/src/WiFiServer.h @@ -58,6 +58,7 @@ class WiFiServer : public Server { virtual size_t write(uint8_t); virtual size_t write(const uint8_t *buf, size_t size); uint8_t status(); + uint16_t port() const; void close(); void stop();