-->
Page 1 of 3

HTTPClient Library vs Manual Code Response Time?

PostPosted: Thu Feb 15, 2018 11:31 am
by androidfanboy
Hi there,

With the ESP8266HTTPClient library using "http.begin()" and "http.GET()" functions the GET requests I am able to read a response very quickly using "payload = http.getString()". However, when using the manual way of connecting with WiFiClient or WiFiClientSecure and sending and receiving the lines manually, it takes up to 5s to read the response from the server. I receive the headers almost immediately after sending, but the actual server response content comes 3-4s after the headers. I use "client.connect()" then use a single "client.print()" line to do a GET request and then use "client.readStringUntil('\n')" to get the headers, then to get the rest of the response. Pretty straightforward and it works, but the responses are slow to come in.

What's the difference here and why is it taking so long doing it manually compared to the HTTPClient functions? Is there something hidden behind the library that I'm missing when doing it manually?

Thanks!

Re: HTTPClient Library vs Manual Code Response Time?

PostPosted: Thu Feb 15, 2018 5:35 pm
by tele_player
you should study the source code for the HTTP client.

Re: HTTPClient Library vs Manual Code Response Time?

PostPosted: Thu Feb 15, 2018 5:56 pm
by androidfanboy
Yea, probably a good idea, I figured that, but was wondering if anyone could point me in the right direction straight away. I'll have to dig in the source code to see what's going on there. It just doesn't make sense that using the default "manual" way would be much slower than using that library, especially since most people probably use the standard WiFiClient library.

Re: HTTPClient Library vs Manual Code Response Time?

PostPosted: Thu Feb 15, 2018 9:05 pm
by tele_player
It is one file, ESP8266HTTPClient.cpp . It’s not difficult to understand.

My first suspicion is that your code isn’t using setNoDelay() on the TCP connection.