How to detect if WiFi client is disonnected?

Thanks to the advice I received here, I'm making good progress porting my Uno Ethernet code to the R4 WiFi. My sketch detects a suitable WiFi network, connects to it, and displays NET on the LED matrix. When my C#.Net app on the PC connects to the R4, it displays APP, and accepts commands from the app, blinking APP each time it receives one. Looking good.

The PC app can disconnect from the R4, then connect again later to send more commands. I would like the matrix to display NET, not APP, when the app disconnects, but I can't figure out how to detect that disconnection.

I've tried code around client.connected() and client.available(), but APP is never replaced with NET.

My code essentially looks like this:

client = server.available();

  if (client)
  {
    if(client.available())
    {
      Serial.println("client.available()");
      displayMatrix(appFrame);  // Display "APP" when control app connected
    }
    else
    {
        Serial.println("NOT client.connected()");
        displayMatrix(netFrame);  // Else display "NET"
      }
    }

Does anyone have any suggestions? Thanks.

--- Mike

if you don't read the incoming bytes, they will be available forever

I'm reading all the incoming bytes. I got it figured out by closely examining and tweaking the code. (Looking for a way to label this thread SOLVED, but done see one.)

--- mike

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.