In the WiFiNINA library the client is available only if it send something to the server but I need to have a connection object available before, just after the connection in accepted.
I saw there is the undocumented method "accept()" of the class "WiFiServer". Someone can give me some information about?
WiFiServer g_theServer(1234);
void setup()
{
// WiFi connection
...
g_theServer.begin();
}
void loop()
{
// Gets a client that is connected to the server and has data available for reading.
WiFiClient theClient = g_theServer.available();
if (theClient)
{}
}
I briefly perused the source (at GitHub - arduino-libraries/WiFiNINA), and this library seems like it's not very well designed. For one, it doesn't have an accept() method, as you pointed out. How is a server to know when a client connects but doesn't send data? The WifiServer::available() method, as the Ethernet library points out, "makes some protocols like FTP impossible to properly implement". And I already found one bug just by looking at the code:
In src/utility/server_drv.cpp:
SpiDrv::sendParam(peek, LAST_PARAM);
That should be:
SpiDrv::sendParam(peek, 1, LAST_PARAM);
The lastParam parameter of sendParam() is the 3rd. The second parameter is param_len.
Yes, to be kind we can say that this library is not very well designed...
I'll do an ugly workaround to proceed with my project and then I'll try to modify the library or write a new one.