Pages: [1]   Go Down
Author Topic: Problem with Hello World EthernetServer  (Read 312 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

I'm trying to do a Hello World Server but my problem is that I don't know the specific problem but I think it's start after void loop() , I need to figure out the problem .

Code:
#include <Ethernet.h>
#include <SPI.h>

byte mac[] = { 0x55 , 0x66 , 0x56 , 0x90 , 0xEE , 0x70 };
byte ip[] = { 192 , 168 , 0, 9 };
byte subnet[] = { 255 , 255 , 255 , 0 };
byte gateway[] = { 192 , 168 , 0 , 1 };
EthernetServer server(84);

void setup(){
  Serial.begin(9600);
  Ethernet.begin(mac,ip,gateway,subnet);
  server.begin();
  Serial.println(Ethernet.localIP());
  Serial.println("Server test1");
}
void loop(){
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean CNT = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
      }
        if( c =='\n' && CNT){
          client.println("HTTP/1.1 204 OK");
          client.println("Content-Type:text/html");
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          client.println("<body>");
          client.println("<h1>Hello World</h1>");
          client.println("</body>");
          client.println("</html>");
       
        }
        client.stop();
    }
   
    }
  }
}
         
   

best ,
Logged

Offline Offline
Edison Member
*
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Could you try the example webserver, http://arduino.cc/en/Tutorial/WebServer

If that is okay, you could return to your sketch and try to find the differences.
Do you open the 'serial monitor' to see the messages ?
Which Arduino board and which shield are you using ?
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 613
Posts: 49236
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I need to figure out the problem .
But, you don't even know what the problem is.

Quote
I don't know the specific problem

How do you expect us to help you, when you are the one with the hardware, the serial monitor data, and the client, but, you haven't shared any output or observations?
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 484
Posts: 18764
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Code:
          client.println("HTTP/1.1 204 OK");
          client.println("Content-Type:text/html");
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          client.println("<body>");
          client.println("<h1>Hello World</h1>");
          client.println("</body>");
          client.println("</html>");

There should be a blank line (sent) before the DOCTYPE line. That separates the HTTP header from the sent HTML.
Logged


Rome, Italy
Offline Offline
Sr. Member
****
Karma: 20
Posts: 442
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why a 204 response? It is like saying "no response" http://www.w3.org/Protocols/HTTP/HTRESP.html
Logged

Pages: [1]   Go Up
Jump to: