user34257: I use an ESP32 to open an access point and listen for TCP connections over a WiFiServer object.
When I get a client on the server I want to know when it has disconnected.
Currently I have a simple piece of code on both the client and the server side. I connect using a TcpClient in C#.
When I call client.close() on the client side, the client.connected() loop on the server just continues forever.
Here is the ESP code:

void setup()
{
   WiFi.mode(WIFI_AP);

   WiFi.softAP("test");

   WiFi.softAPConfig(IPAddress(192, 168, 4, 1), IPAddress(192, 168, 4, 1), IPAddress(255, 255, 255, 0));

   Serial.println(WiFi.localIP());

   server.begin();
}

void loop()
{
    while (!client)
    {
        client = server.available();

        delay(10);
    }

    while (client.connected())
    {
        Serial.println("ok");

        delay(1000);

        client.read();
    }
}

C# code:
static void Main(string[] args)
{
     TcpClient client = new TcpClient("192.168.4.1", 222);

     client.Close();
}


user34261: This is a bug in a previous version of the library as mentioned on 
https://github.com/bportaluri/WiFiEsp/issues/14
You can alternatively use WiFi.softAPgetStationNum() to get the count of stations connected to the AP interface.

user34564: My actual answer
You can try to inquire client.status() as a workaround. When no one is connected it should return 0.
Context
What are you building on? I tried to reproduce your problem but everything works as expected, the serial stops printing "ok" when I disconnect.
Also, what libraries are you using exactly? I included ESP8266WiFi.h and WiFiClient.h.
I used platformio v3.4 on an ESP8266-01 module and a simple Android netcat app as client.

34257: <p>I use an ESP32 to open an access point and listen for TCP connections over a WiFiServer object.</p>

<p>When I get a client on the server I want to know when it has disconnected.</p>

<p>Currently I have a simple piece of code on both the client and the server side. I connect using a TcpClient in C#.</p>

<p>When I call <code>client.close()</code> on the client side, the <code>client.connected()</code> loop on the server just continues forever.</p>

<p>Here is the ESP code:
</p>

<pre class="lang-cpp prettyprint-override"><code>void setup()
{
   WiFi.mode(WIFI_AP);

   WiFi.softAP("test");

   WiFi.softAPConfig(IPAddress(192, 168, 4, 1), IPAddress(192, 168, 4, 1), IPAddress(255, 255, 255, 0));

   Serial.println(WiFi.localIP());

   server.begin();
}

void loop()
{
    while (!client)
    {
        client = server.available();

        delay(10);
    }

    while (client.connected())
    {
        Serial.println("ok");

        delay(1000);

        client.read();
    }
}
</code></pre>

<p>C# code:</p>

<pre class="lang-cpp prettyprint-override"><code>static void Main(string[] args)
{
     TcpClient client = new TcpClient("192.168.4.1", 222);

     client.Close();
}
</code></pre>
 34261: <p>This is a bug in a previous version of the library as mentioned on 
<a href="https://github.com/bportaluri/WiFiEsp/issues/14" rel="nofollow noreferrer">https://github.com/bportaluri/WiFiEsp/issues/14</a></p>

<p>You can alternatively use WiFi.softAPgetStationNum() to get the count of stations connected to the AP interface.</p>
 34564: <p><strong>My actual answer</strong></p>

<p>You can try to inquire <code>client.status()</code> as a workaround. When no one is connected it should return 0.</p>

<p><strong>Context</strong></p>

<p>What are you building on? I tried to reproduce your problem but everything works as expected, the serial stops printing "ok" when I disconnect.</p>

<p>Also, what libraries are you using exactly? I included <code>ESP8266WiFi.h</code> and <code>WiFiClient.h</code>.</p>

<p>I used platformio v3.4 on an ESP8266-01 module and a simple Android netcat app as client.</p>
