Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SocketWrapper - MbedServer modernization (without available() and Print) #793

Merged
merged 1 commit into from
Oct 3, 2024

Conversation

JAndrassy
Copy link
Contributor

@JAndrassy JAndrassy commented Dec 6, 2023

MbedServer didn't manage clients for proper available() and print-to-all-clients. Now available() in derived server classes WiFiClient and EthernetClient is deprecated and accept() is added with the same implementation. Inheriting from Print (Server) is removed. write methods for Print implementation are removed. They never worked.

New are constructor without parameters, begin with parameter port and end() as in the new WiFiS3 library.

The ChatServer examples never worked because they relay on Processing style server.available() and print-to-all-clients.. Removed.

ESP32 core and RP2040 core libraries too don't implement Processing style Servers. Processing style WiFiServer and EthernetServer for these cores and Mbed core is implemented in my NetAPIHelpers library. In my networking libraries WiFiEspAT and EthenetENC the print-to-all-clients is in separate class and in next major version I plan to remove server.available() and point to NetAPIHelpers Server.

This replaces PR #750 and #751

overview of Server implementations in libraries https://github.com/JAndrassy/Arduino-Networking-API/blob/main/ArduinoNetAPILibs.md#server-class

MbedServer didn't manage clients for proper available() and
print-to-all-clients. Now available() in derived server classes is
deprecated and accept() is added with the same implementation.
Inheriting from Print (Server) is removed. write methods for Print
implementation are removed. They never worked.
New are constructor without parameters, begin with parameter port and
operator bool.
@JAndrassy
Copy link
Contributor Author

JAndrassy commented Feb 5, 2024

@facchinm @pennam

now this is my last essential PR for Mbed Core networking. It does changes proposed by Alessandro Ranellucci, but including the consequences

#750 adds accept() in WiFiServer

consequences:

  • add accept in EthernetServer
  • deprecate available
  • modify examples to use accept() and remove Ethernet examples which require true server.available() (WiFi lib doesn't have them)
  • remove unimplemented Print inheritance and write methods, because print-to-all-clients is tied with server.available()

#751 adds end() in WiFiServer

consequences:

  • add end() in EthernetServer

other related server classes modernization as in WiFiS3:

  • add begin with parameter port and constructor without parameters
  • add operator bool

Some context:

The server.available() originates in Processing. It is an idea to simplify a TCP server for artists. But as the lack of proper server.available() here and in multiple third party libraries shows, users not expect that behavior. In most request-response-stop use-cases it doesn't even matter.

Class Server inherits from Print for the print-to-all-clients functionality. This functionality is tied with the available() method implementation. The implementation of the Server class should register all connected clients for correct implementation of available() and for print-to-all-clients functionality.

The base class Server can't declare required server methods available() and accept(), because they have the return type of the specific Client implementation of the library (for example EthernetClient in the Ethernet library). As a consequence, It is not possible to use the base class Server to work with an instance of an inherited server class. So Server is just disguised Print and without Print usage inheriting from Server class is useless.

Copy link
Contributor

@pennam pennam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JAndrassy
Copy link
Contributor Author

JAndrassy commented Oct 3, 2024

it is just a comment which is not true. it is same in the Ethernet library from where the example originates.
I guess it had Serial.write in " // check for incoming data from all clients" section at some point in time.

arduino-libraries/Ethernet@2304c69

@pennam pennam merged commit 4726f25 into arduino:main Oct 3, 2024
11 checks passed
@JAndrassy JAndrassy deleted the mbedserver_modernization branch October 3, 2024 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants