Skip to content

Commit 3e293a4

Browse files
committedAug 1, 2022
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
1 parent be79090 commit 3e293a4

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed
 

‎libraries/SocketWrapper/src/MbedClient.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ void arduino::MbedClient::setSocket(Socket *_sock) {
6060
void arduino::MbedClient::configureSocket(Socket *_s) {
6161
_s->set_timeout(_timeout);
6262
_s->set_blocking(false);
63+
_s->getpeername(&address);
6364

6465
if (event == nullptr) {
6566
event = new rtos::EventFlags;
@@ -99,7 +100,6 @@ int arduino::MbedClient::connect(SocketAddress socketAddress) {
99100
return 0;
100101
}
101102

102-
address = socketAddress;
103103
nsapi_error_t returnCode = static_cast<TCPSocket *>(sock)->connect(socketAddress);
104104
int ret = 0;
105105

@@ -150,8 +150,6 @@ int arduino::MbedClient::connectSSL(SocketAddress socketAddress) {
150150
return 0;
151151
}
152152

153-
address = socketAddress;
154-
155153
restart_connect:
156154
nsapi_error_t returnCode = static_cast<TLSSocket *>(sock)->connect(socketAddress);
157155
int ret = 0;
@@ -304,7 +302,7 @@ IPAddress arduino::MbedClient::remoteIP() {
304302
}
305303

306304
uint16_t arduino::MbedClient::remotePort() {
307-
return 0;
305+
return address.get_port();
308306
}
309307

310308
void arduino::MbedClient::setTimeout(unsigned long timeout) {

0 commit comments

Comments
 (0)
Please sign in to comment.