WiFiSever - Arduino API available() and accept()#7605
Conversation
|
In the years esp8266 Arduino exists, missed someone the true Arduino behaviour of available()? I think not. |
|
now I realized that the Arduino implementation of
maybe a WiFiArduinoServer could inherit from WiFiServer and add the Arduino style available() function and the write-to-all-clients functionality. (same for SSL server) |
That would be a very good first step. |
I rework this PR. Should I use WiFiClient or ClientContext to store the clients? (ClientContext with ref and unref) |
|
I think you have noticed that |
|
this will be the example called PagerServer, a simple server that echoes any incoming messages to all connected telnet clients. I think it is Arduino way elegant. https://github.com/jandrassy/WiFiEspAT/blob/master/examples/Basic/PagerServer/PagerServer.ino |

According to documentation, the
server.available()should return first client with data available.https://www.arduino.cc/en/Reference/WiFiServerAvailable (esp8266 doc points there).
ESP8266WiFi library now does what a new EthernetServer.accept() method does: https://www.arduino.cc/en/Reference/EthernetServerAccept. It was added to Ethernet library by Paul Stoffregen in 2018 for Ethernet 2.0. I added it to UIPEthernet in February and I have it in my WiFiEspAT library too.
This PR shows a draft of a possible implementation of
available(). (This quick implementation could let some client wait to long.)My opinion is that it is strange to have a function like this available(). My explanation how they defined it like this, is that the networking libraries by Arduino are always remote APIs for a firmware and there it doesn't look so strange.