From 3e293a4d3b5395062813d201d2f2d7321bf83d5c Mon Sep 17 00:00:00 2001 From: Romain Reignier Date: Mon, 1 Aug 2022 17:11:20 +0200 Subject: [PATCH] MbedClient: retrieve the address and port from the underlying socket and implement remotePort() Useful for Client retrieved from Server::available() and tested with client example --- libraries/SocketWrapper/src/MbedClient.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libraries/SocketWrapper/src/MbedClient.cpp b/libraries/SocketWrapper/src/MbedClient.cpp index 538005799..dfd856f77 100644 --- a/libraries/SocketWrapper/src/MbedClient.cpp +++ b/libraries/SocketWrapper/src/MbedClient.cpp @@ -60,6 +60,7 @@ void arduino::MbedClient::setSocket(Socket *_sock) { void arduino::MbedClient::configureSocket(Socket *_s) { _s->set_timeout(_timeout); _s->set_blocking(false); + _s->getpeername(&address); if (event == nullptr) { event = new rtos::EventFlags; @@ -99,7 +100,6 @@ int arduino::MbedClient::connect(SocketAddress socketAddress) { return 0; } - address = socketAddress; nsapi_error_t returnCode = static_cast(sock)->connect(socketAddress); int ret = 0; @@ -150,8 +150,6 @@ int arduino::MbedClient::connectSSL(SocketAddress socketAddress) { return 0; } - address = socketAddress; - restart_connect: nsapi_error_t returnCode = static_cast(sock)->connect(socketAddress); int ret = 0; @@ -304,7 +302,7 @@ IPAddress arduino::MbedClient::remoteIP() { } uint16_t arduino::MbedClient::remotePort() { - return 0; + return address.get_port(); } void arduino::MbedClient::setTimeout(unsigned long timeout) {