test ethernet

Dependencies:   EthernetInterface HTTPClient MbedJSONValue mbed-rtos mbed

Revision:
0:1de2607f659c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Oct 20 18:34:54 2017 +0000
@@ -0,0 +1,40 @@
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "HTTPClient.h"
+ 
+int main() {
+    // Ethernet setup
+    EthernetInterface eth;
+    eth.init(); //Use DHCP
+    eth.connect();
+    printf("IP Address is %s\n", eth.getIPAddress());
+    
+    // Http client
+    HTTPClient http;
+    int i = 0;
+    while(i < 100) {
+        TCPSocketConnection sock;
+        sock.connect("mbed.org", 80);
+        
+        char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n";
+        sock.send_all(http_cmd, sizeof(http_cmd)-1);
+        
+        char buffer[300];
+        int ret;
+        while (true) {
+            ret = sock.receive(buffer, sizeof(buffer)-1);
+            if (ret <= 0)
+                break;
+            buffer[ret] = '\0';
+            printf("Received %d chars from server:\n%s\n", ret, buffer);
+        }
+          
+        sock.close();
+        i++;
+        wait(1);
+    }
+    
+    eth.disconnect();
+    
+    while(1) {}
+}
\ No newline at end of file