Go Down

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

bubulindo

Hello,

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); ?
Eu não sou o teu criado. Se respondo no fórum é para ajudar todos mediante a minha disponibilidade e disposição. Responder por mensagem pessoal iria contra o propósito do fórum e por isso evito-o.
Se realmente pretendes que eu te ajude por mensagem pessoal, então podemos chegar a um acordo e contrato onde me pagas pela ajuda que eu fornecer e poderás então definir os termos de confidencialidade do meu serviço. De forma contrária toda e qualquer ajuda que eu der tem de ser visível a todos os participantes do fórum (será boa ideia, veres o significado da palavra fórum).
Nota também que eu não me responsabilizo por parvoíces escritas neste espaço pelo que se vais seguir algo dito por mim, entende que o farás por tua conta e risco.

Dito isto, mensagens pessoais só se forem pessoais, ou seja, se já interagimos de alguma forma no passado ou se me pretendes convidar para uma churrascada com cerveja (paga por ti, obviamente).

PaulS

Quote
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?

SurferTim

Here is a client example sketch that should not run out of sockets.
http://playground.arduino.cc/Code/WebClient
It has my timeout code already in it.

Go Up