TCPServer , help needed please

Is there something missing from the docs about the TCPServer library ?
available() says :-
Gets a client that is connected to the server and has data available for reading.

So is there a read like in TCPclient ? it not in the docs.

Server.available() isn’t letting you know if there’s data to be read, it returns whether or not a client has connected. If so, you can read from that client. See the telnet server example.

O.K I`m a little lost with this one , So for example you use :-

TCPServer server = TCPServer(1234);
TCPClient client;
server.begin(); <-- in setup()

in loop() ****
So a client connects to you on port 1234 ,
you use client.connected() to work out if the client as connected ?
and get any incoming data with client.read() , but send data with server.write()
the docs and the example, makes no sense to me.

Hi @peter_a

The server is just a way of having a client connection that listens for incoming connections and then hands them to you when you call server.available(). The Server begin method just starts listening for connections.

If you look at the example in the docs in loop() it says:

  • If there is a client connected to the server then as long as the client is sending bytes to the server, echo them back using server.write().
  • If there is not a client connected, then set the client to server.available() which will either be an actual client if someone connects or NULL which means there is no one on the line at the moment.

The Arduino example here is very similar but with slightly different control flow. Maybe that will help you understand.