How actually arduino web server example works? (Concept )

Hi guys

first, I apologize for my bad english.

I really need your help
It's really important....

I'm working on some project with A rduino web server and i get turn on and off some led ,but i don't know how to describe the whole web server process.

I am really confussed about arduino web servers examples one the internet, and how it actually works. Arduino supose to be a server, but if I understand that right, the client (web browser) is the one who actually work all the job?

Almost every arduino web server example starts with code in the below. I understand that web browser is client, but don't understand how this actually work :frowning: I also know some basics of HTML, HTTP (request, responese, blank line..), but who actually send the HTTP answer in this example? why it's not used server.write, instead of client.println? So...if you navigate to server with your browser, the page will be opened. But who actually "create" web page? I know that browser first send requst that ends with blank line. After that, arduino "send" web page to the browser or client print the whole web page? The main question is why all of this HTML and server thing is done by client.println?? So, the browser send HTTP requst, and who actually detects newline???? Arduino or client ? I really don't understand this stuff with client.println and what actually Arduino program does, and what client ( web browser) ?

if (client) {

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

if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("");
client.println("");
/....
.. .....
.........
.......

but who actually send the HTTP answer in this example?

The server does, here:

client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");

But who actually "create" web page?

The "web page" is what the browser does with the data between the and tags.

After that, arduino "send" web page to the browser or client print the whole web page?

Yes.

who actually detects newline?

The Arduino as server:

if (c == '\n' && currentLineIsBlank) {

The client.read() is reading data FROM the client. The client.print() is sending data TO the client.

PaulS, thank you very muchhhhhhh!!!! The last sentence explained me everything I was confused about, and now i understand :slight_smile: