Advertisement
shubhamgoyal

conn.stop() doubt

Jul 26th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. void loop(void) {
  2.  
  3. // listen for incoming clients
  4. EthernetClient client = server.available();
  5. if (client) {
  6. Serial.println("new client");
  7. // an http request ends with a blank line
  8. boolean currentLineIsBlank = true;
  9. while (client.connected()) {
  10. if (client.available()) {
  11. char c = client.read();
  12. Serial.write(c);
  13. // if you've gotten to the end of the line (received a newline
  14. // character) and the line is blank, the http request has ended,
  15. // so you can send a reply
  16. if (c == '\n' && currentLineIsBlank) {
  17. // send a standard http response header
  18. client.println("HTTP/1.1 200 OK");
  19. client.println("Content-Type: text/html");
  20. client.println("Connnection: close");
  21. client.println();
  22. client.println("<!DOCTYPE HTML>");
  23. client.println("<html><body>HELLO</body></html>");
  24. break;
  25. }
  26. if (c == '\n') {
  27. // you're starting a new line
  28. currentLineIsBlank = true;
  29. }
  30. else if (c != '\r') {
  31. // you've gotten a character on the current line
  32. currentLineIsBlank = false;
  33. }
  34. }
  35. }
  36. // give the web browser time to receive the data
  37. delay(1);
  38. // close the connection:
  39. client.stop();
  40. Serial.println("client disonnected");
  41. blinkLED();
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement