Donatien Garnier
/
NetHttpClientStreamingExample
Networking stack: HTTP Client Streaming example
Revision 1:0e4f1cc78052, committed 2010-05-27
- Comitter:
- donatien
- Date:
- Thu May 27 11:18:24 2010 +0000
- Parent:
- 0:b6b9d1b95cc7
- Commit message:
Changed in this revision
HttpClientStreamingExample.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/HttpClientStreamingExample.cpp Thu May 27 10:16:27 2010 +0000 +++ b/HttpClientStreamingExample.cpp Thu May 27 11:18:24 2010 +0000 @@ -10,16 +10,11 @@ void request_callback(HttpResult r) { result = r; - printf("\r\n-----Err %d-----\r\n", r); completed = true; } - -Serial pc(USBTX, USBRX); int main() { - pc.baud(115200); - printf("Start\n"); printf("\r\nSetting up...\r\n"); @@ -33,19 +28,20 @@ HttpStream stream; - char BigBuf[1024 + 1] = {0}; - stream.readNext((byte*)BigBuf, 1024); + char BigBuf[512 + 1] = {0}; + stream.readNext((byte*)BigBuf, 512); //Point to buffer for the first read - HttpResult r = http.get("http://mbed.org/", &stream, request_callback); + HttpResult r = http.get("http://hackaday.com/feed/", &stream, request_callback); //Load a very large page, such as the hackaday RSS feed while(!completed) { - Net::poll(); + Net::poll(); //Polls the Networking stack if(stream.readable()) { - BigBuf[stream.readLen()+1] = 0; - printf("%s",BigBuf); - stream.readNext((byte*)BigBuf, 1024); + BigBuf[stream.readLen()] = 0; //Transform this buffer is zero-terminated char* string + printf("%s",BigBuf); //Displays it while loading + //Note: some server do not like if you throttle them too much, so printf'ing during a request is generally bad practice + stream.readNext((byte*)BigBuf, 512); //Buffer has been read, now we can put more data in it } } printf("\r\n--------------\r\n"); @@ -55,7 +51,7 @@ } else { - printf("Error %d\n", r); + printf("Error %d\n", result); } while(1)