user29646: I have a server on my arduino (WiFi) and want to save the clients that connect, so that I can send to them (to each separately) data later. 
Is the best data structure a linked list? How can I see if this client connected already (if there is already a connection to this ip) to avoid doubles? How can I detect when they disconnect in order to delete them?
Of course, I read the ref; but I cannot find the answers there.
Here is my minimal example (The maximum number of simultaneous connections is 5):
EDIT Keep in mind, that I just want to have a simple connection using the WiFiClient/ WiFiServer class and not a HTTP-Webserver
#include <WiFi.h>

WiFiServer server(23);
void setup() {
  server.begin();
}

void loop() {
  WiFiClient client = server.available();

  if (client) {
    //if not seen yet, add to a linked list (?)
  }
}


user10794: 
I have a server on my arduino (WiFi) and want to save the clients that connect, so that I can send to them (to each separately) data later.

The question (and some of the answers) seem to misunderstand how HTTP works. I know how it works (at least to an extent) as I have written server scripts in Lua, as well as C++ for the Arduino.
As I mention in my page about an Arduino HTTP server when the client initiates a request it sends an HTTP header along these lines:
POST /forum/showpost.php?id=12345&page=2 HTTP/1.1
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:39.0)
Host: www.example.com
Cookie: foo=bar;
Accept-Language: en, mi

action=save&user_id=1234

Breaking those parts down you get this:

Once the client has sent the request it awaits (on the same connection) for the server to respond. The response may look something like this:
HTTP/1.1 200 OK
Content-Type: text/html
Connection: close
Server: HTTPserver/1.0.0 (Arduino)

<!DOCTYPE html>
<html>

<head>
<title>Arduino test</title>
</head>

<body>
<h1> My heading </h1>
<p>Some text
</body>
</html>

Notice the blank line between the HTTP header and the actual file data (the HTML data).

Under HTTP 1.1 the server can request that the connection keep open the connection by replacing:
Connection: close

by:
Connection: keep-alive

All this means is that the client is still connected and can now request other stuff (for example an image from an <img> tag). It does that by sending another HTTP header and then getting another response. It doesn't keep the connection open just so that the server can randomly send other stuff in the future.
Note: - the default under HTTP 1.1 is for the connections to be persistent.


... so that I can send to them (to each separately) data later. 

You don't "send data later", that's not how it works. The client may request data later.

The standard way of keeping track of clients which are doing stuff (like filling in a series of forms) is to use cookies - that is what they are for. The server sends a cookie, the client remembers it, and sends it back with the next request. The cookie identifiers that it is the same client as before, and what it was doing. For example, a cookie might contain a token to indicate that you have logged in.

user16085: The WiFiClient.h header and WifiClient.cpp source files are useful for reference.

Is the best data structure a linked list?

Probably not here.  Possibly not ever.  It's a load of effort to implement, and won't give you any benefit.  Just create an array of them:
WiFiClient clients[5];

Then perhaps something like
WiFiClient newClient = server.available();
if (newClient) {
    // TODO: Check whether we have an existing connection from this IP
    // TODO: Get the first 'free' array index
    clients[firstFree] = newClient;
}


How can I see if this client connected already (if there is already a connection to this ip) to avoid doubles?

Get the remote IP address of the new client
IPAddress = newClient.remoteIP();

Do the same with all the connected clients in your array* and compare them.  If you find a match, drop the connection
newClient.disconnect();

and, probably, don't put it in the array.

How can I detect when they disconnect in order to delete them?

if (client[i].connected())

Lastly, how do we keep track of which items in our array are current active connections, and which aren't (either not yet used, or already disconnected).  You could do this several ways.  One would be to iterate through the array, checking whether the item is valid and connected:
// Returns -1 if no free slots
int firstFree() {
    for(int i=0 ; i<5 ; ++i) {
        if(!clients[i] || !clients[i].connected()) return i;
    }
    return -1;
}

All code untested so you may find typos, but I believe it's basically correct.

29646: <p>I have a server on my arduino (WiFi) and want to save the clients that connect, so that I can send to them (to each separately) data later. </p>

<p>Is the best data structure a <em>linked list</em>? How can I see if this client connected already (if there is already a connection to this ip) to avoid doubles? How can I detect when they disconnect in order to delete them?</p>

<p>Of course, I read the <a href="https://www.arduino.cc/en/Reference/WiFi" rel="nofollow noreferrer">ref</a>; but I cannot find the answers there.
Here is my minimal example (The maximum number of simultaneous connections is 5):</p>

<p><strong>EDIT</strong> Keep in mind, that I just want to have a simple connection using the WiFiClient/ WiFiServer class and not a HTTP-Webserver</p>

<pre><code>#include &lt;WiFi.h&gt;

WiFiServer server(23);
void setup() {
  server.begin();
}

void loop() {
  WiFiClient client = server.available();

  if (client) {
    //if not seen yet, add to a linked list (?)
  }
}
</code></pre>
 10794: <blockquote>
  <p>I have a server on my arduino (WiFi) and want to save the clients that connect, so that I can send to them (to each separately) data later.</p>
</blockquote>

<p>The question (and some of the answers) seem to misunderstand how HTTP works. I know how it works (at least to an extent) as I have written server scripts in Lua, as well as C++ for the Arduino.</p>

<p>As I mention in <a href="http://www.gammon.com.au/forum/?id=12942" rel="nofollow noreferrer">my page about an Arduino HTTP server</a> when the client initiates a request it sends an HTTP header along these lines:</p>

<pre><code>POST /forum/showpost.php?id=12345&amp;page=2 HTTP/1.1
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:39.0)
Host: www.example.com
Cookie: foo=bar;
Accept-Language: en, mi

action=save&amp;user_id=1234
</code></pre>

<p>Breaking those parts down you get this:</p>

<p><a href="https://i.stack.imgur.com/NweZT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NweZT.png" alt="HTTP message structure"></a></p>

<p>Once the client has sent the request it awaits (on the same connection) for the server to respond. The response may look something like this:</p>

<pre class="lang-html prettyprint-override"><code>HTTP/1.1 200 OK
Content-Type: text/html
Connection: close
Server: HTTPserver/1.0.0 (Arduino)

&lt;!DOCTYPE html&gt;
&lt;html&gt;

&lt;head&gt;
&lt;title&gt;Arduino test&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;h1&gt; My heading &lt;/h1&gt;
&lt;p&gt;Some text
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>Notice the blank line between the HTTP header and the actual file data (the HTML data).</p>

<hr>

<p>Under HTTP 1.1 the server can request that the connection keep open the connection by replacing:</p>

<pre><code>Connection: close
</code></pre>

<p>by:</p>

<pre><code>Connection: keep-alive
</code></pre>

<p>All this means is that the client is still connected and can now request other stuff (for example an image from an <code>&lt;img&gt;</code> tag). It does that by sending <strong>another</strong> HTTP header and then getting another response. It doesn't keep the connection open just so that the server can randomly send other stuff in the future.</p>

<p><em>Note:</em> - the <strong>default</strong> under HTTP 1.1 is for the connections to be persistent.</p>

<hr>

<blockquote>
  <p>... so that I can send to them (to each separately) data later. </p>
</blockquote>

<p>You don't "send data later", that's not how it works. The client may <strong>request</strong> data later.</p>

<hr>

<p>The standard way of keeping track of clients which are doing stuff (like filling in a series of forms) is to use <strong>cookies</strong> - that is what they are for. The server sends a cookie, the client remembers it, and sends it back with the next request. The cookie identifiers that it is the same client as before, and what it was doing. For example, a cookie might contain a token to indicate that you have logged in.</p>
 16085: <p>The <a href="https://github.com/codebendercc/arduino-library-files/blob/master/libraries/WiFi/WiFiClient.h" rel="noreferrer">WiFiClient.h header</a> and <a href="https://github.com/codebendercc/arduino-library-files/blob/master/libraries/WiFi/WiFiClient.cpp" rel="noreferrer">WifiClient.cpp source</a> files are useful for reference.</p>

<blockquote>
  <p>Is the best data structure a linked list?</p>
</blockquote>

<p>Probably not here.  <a href="https://www.youtube.com/watch?v=YQs6IC-vgmo" rel="noreferrer">Possibly not ever</a>.  It's a load of effort to implement, and won't give you any benefit.  Just create an array of them:</p>

<pre><code>WiFiClient clients[5];
</code></pre>

<p>Then perhaps something like</p>

<pre><code>WiFiClient newClient = server.available();
if (newClient) {
    // TODO: Check whether we have an existing connection from this IP
    // TODO: Get the first 'free' array index
    clients[firstFree] = newClient;
}
</code></pre>

<blockquote>
  <p>How can I see if this client connected already (if there is already a connection to this ip) to avoid doubles?</p>
</blockquote>

<p>Get the remote IP address of the new client</p>

<pre><code>IPAddress = newClient.remoteIP();
</code></pre>

<p>Do the same with all the connected clients in your array* and compare them.  If you find a match, drop the connection</p>

<pre><code>newClient.disconnect();
</code></pre>

<p>and, probably, don't put it in the array.</p>

<blockquote>
  <p>How can I detect when they disconnect in order to delete them?</p>
</blockquote>

<pre><code>if (client[i].connected())
</code></pre>

<p>Lastly, how do we keep track of which items in our array are current active connections, and which aren't (either not yet used, or already disconnected).  You could do this several ways.  One would be to iterate through the array, checking whether the item is valid and connected:</p>

<pre><code>// Returns -1 if no free slots
int firstFree() {
    for(int i=0 ; i&lt;5 ; ++i) {
        if(!clients[i] || !clients[i].connected()) return i;
    }
    return -1;
}
</code></pre>

<p>All code untested so you may find typos, but I believe it's basically correct.</p>
