JAndrassy / WiFiEspAT

Arduino networking library. Standard Arduino WiFi networking API over ESP8266 or ESP32 AT commands.
GNU Lesser General Public License v2.1
271 stars 44 forks source link

[suggestion] new function WiFiClient.localPort() #71

Closed atesin closed 2 years ago

atesin commented 2 years ago

the library currently has a WiFiClient.remotePort() function, but have no WiFiClient.localPort() one... it could be useful, imagine this situation...

we start a server, accept() incoming connections and remember them some way for future use... we can distinguish them by remote ip/port and do something customized action with each them... for example have another lists with connection status, or total data read, or time connected, etc... for this we can distinguish connections by ip/port for example (i.e. socket: srcIp:srcPort:dstIp:dstPort)

suppose at some time we need to retrieve simultaneously some data from another server to continue, still keeping connections sorted and managed.... but the remote port will be always fixed, meaning if we open 2 connections we will have no way to dstinguish them... in this case (as client) we could distinguish them by local port since it will be random, but currently there is no way to get it to craft the socket name :(

JAndrassy commented 2 years ago

done

JAndrassy commented 2 years ago

note that a connection closed in AT firmware may be still open in library if it has cached data not read by the sketch. then the remoteIP, remotePort and localPort will return zeros.

atesin commented 2 years ago

excelent!... so the 0-value is the "standard" behavior for closed connections parameters... could even be useful to identify early those with unread data

keep in mind this new function is not present in wifinina api, so you will have to put in documentation also

(wifiespat: the best esp8266 arduino lib!)

JAndrassy commented 2 years ago

client.status() returns CLOSED or ESTABLISHED

atesin commented 2 years ago

just as a complement, imagine this other inverse situation...

JAndrassy commented 2 years ago

I closed this issue when I added WiFiClient.localPort(). what is the problem?

atesin commented 2 years ago

none, sorry, i get confused xD