Hi everyone, I have a problem with a class, this class is about a web server, I declared two members: server and client, the type of the members are EthernetServer and EthernetClient respectively, but, when i created an object from the class, the member server do not work, when i try access by the browser with the ip address nothing happens, i will attach the code, i hope someone can help me, please
#include "SPI.h"
#include "Ethernet.h"
class EthernetHTTPServer {
private:
EthernetServer server;
EthernetClient client;
public:
EthernetHTTPServer(unsigned int port = 80): server(port), client() {
server.begin();
}
bool listen() {
client = server.available();
if(client != false) {
while(client.available()) {
Serial.write(client.read());
}
client.print("HTTP/1.1 200 OK\r\n");
client.print("Content-Type: text/html\r\n");
client.print("Connection: close\r\n");
client.print("\r\n");
client.print("<!DOCTYPE html>\r\n");
client.print("<html>\r\n");
client.print("<head>\r\n");
client.print("<meta charset=\"UTF-8\">\r\n");
client.print("<title>Hello World!</title>\r\n");
client.print("</head>\r\n");
client.print("<body>\r\n");
client.print("<p>Hello World!</p>\r\n");
client.print("</body>\r\n");
client.print("</html>\r\n");
client.flush();
client.stop();
}
}
};
EthernetHTTPServer server;
void setup() {
unsigned char mac[] = {0xf4, 0xd2, 0xa1, 0x44, 0xc2, 0xb3};
Ethernet.begin(mac);
Serial.begin(9600);
Serial.print("Server at: ");
Serial.print(Ethernet.localIP());
Serial.print("\r\n");
}
void loop() {
server.listen();
}