how ethernt library methods work

Hello. I need to periodically send data on the internet and I am sucessfully using the official ethernet shield and library The arduino only acts as CLIENT.
What I am doing is this:
A) Check if the connection in ON client.connected()
B) if not connect client.connect()
C) send data
D) while client.connected() read and parse server answer
E) once obtained the right answer or once a timout elapses call client.stop()

This works but I may be I can make it better understanding more deep what ethernet methods do.
My questions (unresolved afer reading the internet reference and the library code) are:

  1. Does client.connected checks if the connection is opened only SERVER SIDE speaking? (On TCP it is like we have 2 connections, one server side and one client side).
  2. If point "A" give false do I have do call stop() before call the connect() on point "B".
  3. Does the stop() funtion only close the connection client side speaking? (I call the close every time I send data because I know it is not a good practice to leave too much connection opened to the server, but if it acts only only on client side...)

Thanks for you help if you could answer!

  1. Does client.connected() checks if the connection is opened only SERVER SIDE speaking? (On TCP it is like we have 2 connections, one server side and one client side).

This depends, in part on whether the Arduino is a client or a server. If it is a server, the client.connected() method returns true if there is a connection from a client that needs to be dealt with. You are free to look at the source code to see for yourself.

On TCP, there is a client end to the connection and a server end. Since TCP is what is used in the Ethernet class, by default, the same is true in the Ethernet class.

The Ethernet class can't tell the status of the connection on the other end. All that it knows is that it got a request for data, so client.connect() returns true.

  1. If point "A" give false do I have do call stop() before call the connect() on point "B".

What are point "A" and point "B"? They don't make sense.

If there is no client connected, there is nothing to stop.

  1. Does the stop() funtion only close the connection client side speaking? (I call the close every time I send data because I know it is not a good practice to leave too much connection opened to the server, but if it acts only only on client side...)

It closes the Arduino end of the connection, making it available for reuse.

Remember this is open source - you can go look at the code yourself to answer such questions - in fact this is often a more reliable guide than the documentation which might be incomplete, out of date. Reading someone else's code is a good thing - you might learn something, you might spot a bug (and get the kudos of suggesting a fix to the author). You might spot a way to extend/improve the library too.

Thanks. I edit the question specifing that I am using arduino always as a client.

The Ethernet class can't tell the status of the connection on the other end

but so how ethernet client.connected() can works? (I have read the code but I can't understand how readSnSR() works)

If there is no client connected, there is nothing to stop.

but in many official examples you can find:

if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
for(;;)
;
}

MarkT:
you can go look at the code yourself to answer such questions

Of course before ask you have to check yourself... If I have asked it is because after looking at the code, arduino docs and technical docs about TCP connections I did not succed. Answers like your made the forum heavy to read. Anyway it's true that sometimes people ask thing they can solve by themselves but this discussion is out of topic.

Here is the client code I use. It shows how all that should be used together.

Keep checking/reading until the server closes the connection, then close your end. Here is the basic response read.

while(client.connected()) {
  while(client.available()) {
    Serial.write(client.read());
  }
}
client.stop();

It does not include a timeout. That is included in the last post on that thread above.

edit: One too many brackets in that code above. Corrected.

the code of ethernet have little bit difficult, i am a newbie

thank you SurferTim.