This is a test program

Dependencies:   EthernetInterface mbed-rtos mbed

Fork of TCPSocket_HelloWorld by mbed official

Revision:
7:65188f4a8c25
Parent:
5:01f6c3e112af
Child:
9:4757a976148d
--- a/main.cpp	Mon Jul 23 11:53:08 2012 +0000
+++ b/main.cpp	Wed Jul 25 15:00:43 2012 +0000
@@ -1,34 +1,32 @@
 #include "mbed.h"
 #include "EthernetInterface.h"
 
-int main() 
-{
+int main() {
     EthernetInterface eth;
     eth.init(); //Use DHCP
     eth.connect();
     printf("IP Address is %s\n", eth.getIPAddress());
     
-    TCPSocket sock;
+    TCPSocketConnection sock;
     sock.connect("mbed.org", 80);
     
     char http_cmd[] = "GET /media/uploads/donatien/hello.txt HTTP/1.1\r\nHost: %s\r\n\r\n";
-    sock.send(http_cmd, sizeof(http_cmd) - 1, 3000);
-
-    char in_buf[256];      
-    bool firstIteration = true;
+    sock.send_all(http_cmd, sizeof(http_cmd) - 1, 3000);
+    
+    char in_buf[256];
     int ret;
-    do
-    {
-        ret = sock.receive(in_buf, 255, firstIteration?3000:0);
+    while (true) {
+        ret = sock.receive(in_buf, 255, 100);
+        if (ret <= 0)
+            break;
+        
         in_buf[ret] = '\0';
-        
         printf("Received %d chars from server: %s\n", ret, in_buf);
-        firstIteration = false;
-    } while( ret > 0 );
+    }
       
-    sock.close();  
+    sock.close();
     
-    eth.disconnect();  
+    eth.disconnect();
     
     while(1) {
     }