ECE 4180 Lab 2 Part 4
Dependencies: EthernetInterface mbed-rtos mbed
Fork of TCPSocket_HelloWorld by
main.cpp
00001 #include "mbed.h" 00002 #include "EthernetInterface.h" 00003 00004 Serial pc(USBTX, USBRX); 00005 00006 int main() 00007 { 00008 pc.printf("Hi! "); 00009 00010 char mac[6]; 00011 mbed_mac_address(mac); 00012 pc.printf("mbed MAC address is %02x:%02x:%02x:%02x:%02x:%02x\n\r", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); 00013 00014 pc.printf("1"); 00015 EthernetInterface eth; 00016 pc.printf("2"); 00017 eth.init(); //Use DHCP 00018 pc.printf("3"); 00019 eth.connect(); 00020 pc.printf("IP Address is %s\n", eth.getIPAddress()); 00021 00022 TCPSocketConnection sock; 00023 sock.connect("mbed.org", 80); 00024 00025 char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n"; 00026 sock.send_all(http_cmd, sizeof(http_cmd)-1); 00027 00028 char buffer[300]; 00029 int ret; 00030 while (true) { 00031 ret = sock.receive(buffer, sizeof(buffer)-1); 00032 if (ret <= 0) 00033 break; 00034 buffer[ret] = '\0'; 00035 pc.printf("Received %d chars from server:\n%s\n", ret, buffer); 00036 } 00037 00038 sock.close(); 00039 00040 eth.disconnect(); 00041 00042 while(1) {} 00043 }
Generated on Tue Jul 12 2022 20:02:41 by 1.7.2