jim hamblen / Mbed OS 4180TCPSocket_Example

Files at this revision

API Documentation at this revision

Comitter:
4180_1
Date:
Thu Feb 04 20:17:42 2021 +0000
Parent:
2:50f1485931f1
Commit message:
ver 1.0

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Jun 23 14:13:09 2017 -0500
+++ b/main.cpp	Thu Feb 04 20:17:42 2021 +0000
@@ -7,27 +7,28 @@
 // Socket demo
 int main() {
     // Bring up the ethernet interface
-    printf("Ethernet socket example\n");
+    printf("\n\rEthernet socket example\n\r");
     net.connect();
 
     // Show the network address
     const char *ip = net.get_ip_address();
-    printf("IP address is: %s\n", ip ? ip : "No IP");
+    printf("IP address is: %s\n\r", ip ? ip : "No IP");
 
     // Open a socket on the network interface, and create a TCP connection to mbed.org
     TCPSocket socket;
     socket.open(&net);
-    socket.connect("www.arm.com", 80);
+    socket.connect("hamblen.ece.gatech.edu", 80);
 
     // Send a simple http request
-    char sbuffer[] = "GET / HTTP/1.1\r\nHost: www.arm.com\r\n\r\n";
+    char sbuffer[] = "GET /hello.txt HTTP/1.1\r\nHost: hamblen.ece.gatech.edu\r\n\r\n";
     int scount = socket.send(sbuffer, sizeof sbuffer);
+    //print out packet
     printf("sent %d [%.*s]\n", scount, strstr(sbuffer, "\r\n")-sbuffer, sbuffer);
 
-    // Recieve a simple http response and print out the response line
-    char rbuffer[64];
+    // Recieve a simple http response and print out the response line and text
+    char rbuffer[400]; //enough for a very short text page - almost out of RAM!
     int rcount = socket.recv(rbuffer, sizeof rbuffer);
-    printf("recv %d [%.*s]\n", rcount, strstr(rbuffer, "\r\n")-rbuffer, rbuffer);
+    printf("recv %d [%.*s]\n\r", rcount, strstr(rbuffer, "\r\n"), rbuffer);
 
     // Close the socket to return its memory and bring down the network interface
     socket.close();