client.stop() is not closing the socket

My arduino client is sending http request to my server every minutes. (Actually there are two http request in every minutes- one to get some data and one to execute a php script. I have been getting a warning message in mysql. After hours of searching I came to a conclusion that client.stop() at the end of the http request is not closing the connection. (That is the basic reason for the warning). I have seen that some people reported the same error before. Any suggestions please

//error message.  it goes on ever minutes- 2 warnings per minutes- 2 http requests!

2019-08-27 10:35:26 32 [Warning] Aborted connection 32 to db: 'unconnected' user: 'root' host: '192.168.xx.xxx' (Got an error reading communication packets)
2019-08-27 10:35:26 35 [Warning] Aborted connection 35 to db: 'unconnected' user: 'root' host: '192.168.xx.xxx' (Got an error reading communication packets)

2019-08-27 10:36:26 36 [Warning] Aborted connection 36 to db: 'unconnected' user: 'root' host: '192.168.xx.xxx' (Got an error reading communication packets)
2019-08-27 10:36:26 39 [Warning] Aborted connection 39 to db: 'unconnected' user: 'root' host: '192.168.xx.xxx' (Got an error reading communication packets)

I used the program from JsonHttpClient.ino | ArduinoJson 5

dayDreamer1013:
My arduino client is sending http request to my server every minutes. (Actually there are two http request in every minutes- one to get some data and one to execute a php script. I have been getting a warning message in mysql. After hours of searching I came to a conclusion that client.stop() at the end of the http request is not closing the connection. (That is the basic reason for the warning). I have seen that some people reported the same error before. Any suggestions please

//error message.  it goes on ever minutes- 2 warnings per minutes- 2 http requests!

2019-08-27 10:35:26 32 [Warning] Aborted connection 32 to db: 'unconnected' user: 'root' host: '192.168.xx.xxx' (Got an error reading communication packets)
2019-08-27 10:35:26 35 [Warning] Aborted connection 35 to db: 'unconnected' user: 'root' host: '192.168.xx.xxx' (Got an error reading communication packets)

2019-08-27 10:36:26 36 [Warning] Aborted connection 36 to db: 'unconnected' user: 'root' host: '192.168.xx.xxx' (Got an error reading communication packets)
2019-08-27 10:36:26 39 [Warning] Aborted connection 39 to db: 'unconnected' user: 'root' host: '192.168.xx.xxx' (Got an error reading communication packets)






I used the program from https://arduinojson.org/v5/example/http-client/

add client.stop() to all 'exits'. now it si closed only on sucess

client.stop() at the end of the http request is not closing the connection

it will close the connexion but a client is considered connected if the connection has been closed but there is still unread data. Just empty the stream before closing:

 while (client.available()) client.read();
client.stop();

or faster

 while (client.read() != -1);
client.stop();
1 Like

I tried this. Didn't make any change. same warnings. 2 warnings per minute.

was that an answer to me or to @Juraj?

you mean you are getting this with the very same exact code from JsonHttpClient.ino | ArduinoJson 5 or did you change something?

also best to move to version 6, here is the updated example

J-M-L:
it will close the connexion but a client is considered connected if the connection has been closed but there is still unread data. Just empty the stream before closing:

 while (client.available()) client.read();

client.stop();


or faster

while (client.read() != -1);
client.stop();

connected() returns true if data are available, but it has no implication for stop()

It still uses “an instance” - not sure how they are garbage collected / cleaned up or if there is a cap to the number of client that can hang around (would need to check source code one of those days)

J-M-L:
It still uses “an instance” - not sure how they are garbage collected / cleaned up or if there is a cap to the number of client that can hang around

after stop() the data are not available.
the buffers are in the Wiznet chip

OK - how/when is the buffer freed when the client instance goes out of scope?

J-M-L:
OK - how/when is the buffer freed when the client instance goes out of scope?

it is in the Wiznet chip firmware, the library doesn't care.
I assume at connection close the firmware resets the buffers

Ok

What’s weird is that the statement « client is considered connected if the connection has been closed but there is still unread data »

How do you understand that?