Hi again,
I've thought about it over the day and think the right way to implement a log function would be as HTTPHandler like:
Core/TCPItem.h:
...
void open();
struct tcp_pcb *pcb() { return _pcb; }
protected:
...
HTTPServer/HTTPLog.h
#ifndef HTTPLOG_H
#define HTTPLOG_H
#include "HTTPServer.h"
class HTTPLog : public HTTPHandler {
public:
HTTPLog(const char *prefix) : HTTPHandler(prefix) {
}
private:
virtual HTTPHandle action(HTTPConnection *con) const {
struct ip_addr ip = con->pcb()->remote_ip;
printf("%hhu.%hhu.%hhu.%hhu %s %s", (ip.addr)&0xFF, (ip.addr>>8)&0xFF, (ip.addr>>16)&0xFF, (ip.addr>>24)&0xFF, (con->getType() == POST? "POST" : "GET"), con->getURL());
return HTTP_AddFields;
}
};
#endif
And main.cpp:
#include "HTTPLog.h"
...
HTTPServer *http = new HTTPServer();
http->addHandler(new HTTPLog("/"));
... // Other Handler
What do you think?
Rolf
In the middle of my mbed ethernet server code I have this line to print out the local IP on my LCD:
Can anyone tell me how to get the remote connected client IP so I can print that on my LCD also? I'd like to log each connection to the server.
I've been searching the libraries for two hours so far with no answer.
Scott