Go Down

Topic: After many connections EthernetClient fails to connect. (Read 479 times) previous topic - next topic



I have a piece of code connecting to a server to collect some data to put display in an LCD, but after some successful connections the EthernetClient fails to connect until I reset the board.

I had a look at the EthernetClient library and changed it to give different error codes (for me to understand what is stopping the program) and what makes my connection fail is this bit of code in EthernetClient.cpp line 39:

Code: [Select]

  if (_sock != MAX_SOCK_NUM)
    return -10; //was 0, troubleshooting

As I read it, if the socket number is different than 4 it fails. Why is that? Especially since it is possible to define the socket number to use by doing

Code: [Select]
EthernetClient client(0); ?
This... is a hobby.


As I read it, if the socket number is different than 4 it fails. Why is that?

How is that failing? 0 usually means no error occurred.

The value in _sock is incremented, from 0, each time a connection is made. If the value gets to be 4, that represents the 5th or 4 connections that can be pending. That is a cause for failure.

If you are not closing the client connection correctly, by reading all the data that the server sends, it is possible to run out of sockets. Then, you need to reset to force the connections to be closed.

So, where is your code?


Here is a client example sketch that should not run out of sockets.
It has my timeout code already in it.

Go Up