You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
WiFi shield client does not release socket on connect fail (with fix) #1720
The wifi shield client code is not releasing the socket when the connection fails. This results in the client using all the sockets in 4 failed attempts, and the connection will fail until the Arduino is reset/rebooted.
IDE v1.0.5 and v1.5.5.
Here is the fix. This is in WiFiClient.cpp
int WiFiClient::connect(IPAddress ip, uint16_t port) {
_sock = getFirstSocket();
if (_sock != NO_SOCKET_AVAIL)
{
ServerDrv::startClient(uint32_t(ip), port, _sock);
WiFiClass::_state[_sock] = _sock;
unsigned long start = millis();
// wait 4 second for the connection to close
while (!connected() && millis() - start < 10000)
delay(1);
if (!connected())
{
// Add this
WiFiClass::_state[_sock] = -1;
// end of add
return 0;
}
}else{
Serial.println("No Socket available");
return 0;
}
return 1;
}
No. This is a separate issue. UDP does not establish a connection like TCP. The section of code this bug is in has nothing to do with UDP. I provided a fix above that has been tested. It was simply a single line omission in the code.
If you think it is the same, install the fix above and try UDP. It won't fix the UDP problem.
This is tested on IDE v1.0.5 with the v1.1.0 firmware upgrade.
I tested UDP and did not find the socket release problem discussed in the other issue.
Here is my socket test. Install it and call it between UDP transactions. It was instrumental in troubleshooting the client socket fail.
void ShowSockStatus() {
for(int x = 0; x < MAX_SOCK_NUM; x++) {
Serial.print(WiFi._state[x]);
Serial.print(" ");
Serial.println(WiFi._server_port[x]);
}
}
I tried the fix you suggested, but even after calling client.close(), I still have some ports in use. I'm using IDE 1.0.5-r2 and WiFi shield firmware 1.1.0
Activity
fpoto commentedon Dec 7, 2013
If I am not wrong, this should be merged with #1637.
SurferTim commentedon Dec 7, 2013
No. This is a separate issue. UDP does not establish a connection like TCP. The section of code this bug is in has nothing to do with UDP. I provided a fix above that has been tested. It was simply a single line omission in the code.
If you think it is the same, install the fix above and try UDP. It won't fix the UDP problem.
This is tested on IDE v1.0.5 with the v1.1.0 firmware upgrade.
I tested UDP and did not find the socket release problem discussed in the other issue.
Here is my socket test. Install it and call it between UDP transactions. It was instrumental in troubleshooting the client socket fail.
ilovetogetspamed commentedon Jun 20, 2014
...
// wait 4 second for the connection to close
while (!connected() && millis() - start < 10000)
...
I believe that is 10 seconds, not 1 second. I.e. 1000 ms = 1 second. 10000 ms = 10 seconds.
danolson1 commentedon Sep 10, 2014
I tried the fix you suggested, but even after calling client.close(), I still have some ports in use. I'm using IDE 1.0.5-r2 and WiFi shield firmware 1.1.0
agdl commentedon Jul 12, 2016
This issue was moved to arduino-libraries/WiFi#5