Hi!
I was reading about the tech-specifications of the Arduino's Ethernet Shield that I'm using. It says the following:
The Wiznet W5100 provides a network (IP) stack capable of both TCP and UDP. It supports up to four simultaneous socket connections.
As I know, when modern browsers send an HTTP request they define in the headers that the connection has to be maintained. Here's an example of a Firefox HTTP request:
GET /favicon.ico HTTP/1.1
Host: 192.168.1.11:5400
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0
Accept: */*
Accept-Language: es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
My question is: if in the HTTP response I define Connection: close is the connection socket for this connection released? Or the connection socket is released with client.stop() instruction?
If you see the stop() function it seems that it's responsible to close the socket, but I'm not sure. Here's the function:
void EthernetClient::stop() {
if (_sock == MAX_SOCK_NUM)
return;
// attempt to close the connection gracefully (send a FIN to other side)
disconnect(_sock);
unsigned long start = millis();
// wait up to a second for the connection to close
uint8_t s;
do {
s = status();
if (s == SnSR::CLOSED)
break; // exit the loop
delay(1);
} while (millis() - start < 1000);
// if it hasn't closed, close it forcefully
if (s != SnSR::CLOSED)
close(_sock);
EthernetClass::_server_port[_sock] = 0;
_sock = MAX_SOCK_NUM;
}
And my final question is: if the socket is realised with client.stop(), it's better to define Connection: close or Connection: keep-alive? It's possible that close is better because the browser will stop trying to be connected to the Arduino?
PS: the Arduino is working as a server and the clients are the browsers.