esp8266 / esp8266/Arduino

WiFiClient.connected() returns false while data are still available in receive buffer

Aperta
#6,701 11 commenti 0 reazioni 1 assegnatario Rivendicata da @d-a-v Vedi su GitHub
Lingua principale
C++
Stelle
16.7k
Fork
13.1k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

### Basic Infos

- [x ] This issue complies with the [issue POLICY doc](https://github.com/esp8266/Arduino/blob/master/POLICY.md).
- [x ] I have read the documentation at [readthedocs](https://arduino-esp8266.readthedocs.io/en/latest) and the issue is not addressed there.
- [x ] I have tested that the issue is present in current master branch (aka latest git).
- [x ] I have searched the issue tracker for a similar issue.
- [x ] If there is a stack dump, I have decoded it.
- [ x] I have filled out all fields below.

#### Platform

- Hardware: [ESP-12|ESP-01|ESP-07|ESP8285 device|other]
- Core Version: [since 2.4.2]
- Development Env: [Arduino IDE|Platformio|Make|other]
- Operating System: [Windows|Ubuntu|MacOS]

### Settings in IDE

- Module: [Generic ESP8266 Module|Wemos D1 mini r2|Nodemcu|other]
- Flash Mode: [qio|dio|other]
- Flash Size: [4MB/1MB]
- lwip Variant: [v1.4|v2 Lower Memory|Higher Bandwidth]
- Reset Method: [ck|nodemcu]
- Flash Frequency: [40Mhz]
- CPU Frequency: [80Mhz|160MHz]
- Upload Using: [OTA|SERIAL]
- Upload Speed: [115200|other] (serial upload only)

### Problem Description

WiFiClient.connected() and WiFiClient bool() operator [should return true while data are available](https://www.arduino.cc/en/Reference/WiFiClientConnected) in receive buffer. Commit https://github.com/esp8266/Arduino/commit/b08d282673055b4758cd73d3cd99573f619112a5#diff-a5fd274181d082a3211a59cb42a7e0d8 released in 2.4.2 changed this.

The SSL Clients have it right.

### [MCVE](https://stackoverflow.com/help/mcve) Sketch

```cpp

#include

#include

#ifndef STASSID
#define STASSID "your-ssid"
#define STAPSK "your-password"
#endif

const char* ssid = STASSID;
const char* pass = STAPSK;

const char* server = "arduino.cc";

WiFiClient client;

void setup() {
Serial.begin(115200);
delay(10);

Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.mode(WIFI_STA);
WiFi.begin(ssid, pass);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");

Serial.println("Starting connection to server...");
if (client.connect(server, 80)) {
Serial.println("connected to server");
client.println("GET /asciilogo.txt HTTP/1.1");
client.print("Host: ");
client.println(server);
client.println("Connection: close");
client.println();
}
}

void loop() {

if (client.available()) {
char c = client.read();
Serial.write(c);
}

if (!client.connected()) {
Serial.println();
Serial.println("disconnecting from server.");
client.stop();

while (true) {
delay(100);
}
}
}

```

### Debug Messages

```
Connecting to ---
.........
WiFi connected
Starting connection to server...
connected to server
HTTP/1.1 200 OK
Server: nginx
Date: Sat, 02 Nov 2019 05:32:18 GMT
Content-Type: text/plain
Content-Length: 2263
Last-Modified: Wed, 02 Oct 2013 13:46:47 GMT
Connection: close
Vary: Accept-Encoding
ETag: "524c23c7-8d7"
Accept-Ranges: bytes

`:;;;,` .:;;:.
.;;;;;;;;;;;` :;;;;;;;;;;: TM
`;;;;;;;;;;;;;;;` :;;;;;;;;;;;;;;;
:;;;;;;;;;;;;;;;;;; `;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;; .;;;;;;;;;;;;;;;;;;;;
;;;;;;;;:` `;;;;;;;;; ,;;;;;;;;.` .;;;;;;;;
.;;;;;;, :;;;;;;; .;;;;;;; ;;;;;;;
;;;;;; ;;;;;;; ;;;;;;, ;;;;;;.
,;;;;; ;;;;;;.;;;;;;` ;;;;;;
;;;;;. ;;;;;;;;;;;` ``` ;;;;;`
;;;;; ;;;;;;;;;, ;;; .;;;;;
`;;;;: `;;;;;;;; ;;; ;;;;;
,;;;;` `,,,,,,,, ;;;;;;; .,,;;;,,, ;;;;;
:;;;;` .;;;;;;;; ;;;;;, :;;;;;;;; ;;;;;
:;;;;` .;;;;;;;; `;;;;;; :;;;;;;;; ;;;;;
.;;;;. ;;;;;;;. ;;; ;;;;;
;;;;; ;;;;;;;;; ;;; ;;;;;
;;;;; .;;;;;;;;;; ;;; ;;;;;,
;;;;;; `;;;;;;;;;;;; ;;;;;
`;;;;;, .;;;;;; ;;;;;;;
disconnecting from server.
```

the HTTP response is cut, because immediately after last TCP packet the TCP connection is closed by HTTP server and connected() returns false

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.