main.cpp

#include "mbed.h"
#include "EthernetNetIf.h"
#include "WIZ820ioNetIf.h"
#include "HTTPClient.h"
#include "HTTPServer.h"
#include <assert.h>

Serial pc(USBTX, USBRX);

//#define MBED_ETH

#ifdef MBED_ETH
EthernetNetIf eth;
#else
WIZ820ioNetIf eth;
#endif

HTTPServer svr;
HTTPClient http1,http2;
HTTPText txt1,txt2;

void callback1(HTTPResult r) {
    printf("callback1(%d)\n", r);
    if (r == HTTP_OK) {
        printf("%s\n", txt1.gets());
    }
}

void callback2(HTTPResult r) {
    printf("callback2(%d)\n", r);
    if (r == HTTP_OK) {
        printf("%s\n", txt2.gets());
    }
}

int main() {
    pc.baud(460800);
    int err = eth.setup();
    assert(err == 0);
    svr.addHandler<SimpleHandler>("/");
    svr.bind(80);
#ifdef MBED_ETH
    while(1) {
        Net::poll();
    }
#endif    
    for(int i = 0; i < 60; i++) {
        const char* url = "http://va009039.appspot.com/mbed/"; 
        http1.get(url, &txt1, callback1);
        http2.get(url, &txt2, callback2);
        Timer t;
        t.reset();
        t.start();
        while(t.read() < 30) {
            Net::poll();
        }
    }
}