O
O
oc1tane2018-01-31 01:19:50
Arduino
oc1tane, 2018-01-31 01:19:50

What is the difference between these two codes?

I am studying the syntax of arduino programs .. I can’t delve into the physical process, what is the difference between the two codes when a client appears?
Code #1

EthernetClient client = server.available();
  if (client) {
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        if (c == '\n' && currentLineIsBlank) {
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  
          client.println();
      <b><HTML></b>
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }

Code #2
EthernetClient client = server.available();
if (client) { 
  index = 0;
  boolean current_line_is_blank = true;
  while (client.connected()) {
  if (client.available()) {
     char c = client.read();
     if (c != '\n' && c != '\r') {
        clientline[index] = c;
        index++;
        if (index >= BUFSIZ) index = BUFSIZ - 1;
        continue;
}

                
      clientline[index] = 0;
      filename = 0;

In terms of page opening speed, code number 2 wins. The bottom line is that I'm trying to bind ajax (so as not to update the parameters), but in the manuals and tutorials, the example is mainly given using code #1.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
CityCat4, 2018-01-31
@CityCat4

Because in the first code there are four client.println() calls, which are not in the second one. How fast is one call? And in the second, the usual symbolic comparisons and assignments.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question