Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.

Commit 36b6b5a

Browse files
committed
fix exception if trying to ack closed connection
1 parent 92de1a0 commit 36b6b5a

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

examples/SyncClient/SyncClient.ino

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ const char* password = "************";
1313

1414
void setup(){
1515
Serial.begin(115200);
16-
WiFi.mode(WIFI_STA);
1716
WiFi.begin(ssid, password);
1817
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
1918
Serial.printf("WiFi Failed!\n");
2019
return;
2120
}
21+
Serial.printf("WiFi Connected!\n");
22+
Serial.println(WiFi.localIP());
2223
#ifdef ESP8266
2324
ArduinoOTA.begin();
2425
#endif
@@ -29,14 +30,15 @@ void setup(){
2930
return;
3031
}
3132
client.setTimeout(2);
32-
if(client.printf("GET / HTTP/1.1\r\nHost: www.google.com\r\n\r\n") > 0){
33-
while(!client.available())
33+
if(client.printf("GET / HTTP/1.1\r\nHost: www.google.com\r\nConnection: close\r\n\r\n") > 0){
34+
while(client.connected() && client.available() == 0){
3435
delay(1);
35-
while(client.connected()){
36-
while(client.connected() && client.available() == 0) delay(1);
37-
while(client.connected() && client.available()){
38-
Serial.write(client.read());
39-
}
36+
}
37+
while(client.available()){
38+
Serial.write(client.read());
39+
}
40+
if(client.connected()){
41+
client.stop();
4042
}
4143
} else {
4244
client.stop();

src/SyncClient.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,9 @@ int SyncClient::read(uint8_t *data, size_t len){
257257
_rx_buffer = _rx_buffer->next;
258258
size_t toRead = b->available();
259259
readSoFar += b->read((char*)(data+readSoFar), toRead);
260-
_client->ack(b->size() - 1);
260+
if(connected()){
261+
_client->ack(b->size() - 1);
262+
}
261263
delete b;
262264
}
263265
if(_rx_buffer != NULL && readSoFar < len){

0 commit comments

Comments
 (0)