Description
The WiFiServer object only contains a constructor that accepts a uint16_t for the port number. It would be nice to allow the user to use an empty constructor and then define the port later.
Additionally, the begin() function's return value is void, meaning that the user has no way of knowing whether it succeeded or not, unless they use the other form of the begin() function which takes a uint8_t as a parameter, but users may not know what to pass in for that parameter, especially when all they want to do is get the result from the begin() function.
Creating an empty constructor would be dirt simple:
WiFiServer::WiFiServer() :
_socket(-1)
{
//empty
}
We can then provide 2 new forms of the begin() function. For the sake of this post, I will call this new function beginWithResult because it returns the result.
One form of the function takes a uint16_t port as a parameter, allowing the user to specify the port when they call begin() rather than when they construct the object. The other form of the function assumes a port has already been defined. Here are the two new functions:
uint8_t WiFiServer::beginWithResult (uint16_t port)
{
_port = port;
return beginWithResult();
}
uint8_t WiFiServer::beginWithResult ()
{
return begin(0);
}
I've already made these code changes in my own fork of the repository, and I would be happy to submit a pull request. I think these changes would really improve the usage of the WiFiServer class.