CodeShare
Dependencies: EthernetInterface mbed-rtos mbed
Fork of 4180_Lab2_TCPSocket_HelloWorld by
main.cpp
- Committer:
- jeremycai3721
- Date:
- 2016-09-25
- Revision:
- 15:d64c0edea178
- Parent:
- 11:59dcefdda506
File content as of revision 15:d64c0edea178:
#include "mbed.h" #include "EthernetInterface.h" Serial pc(USBTX, USBRX); int main() { EthernetInterface eth; eth.init(); //Use DHCP eth.connect(); pc.printf("IP Address is %s\n", eth.getIPAddress()); 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) { pc.printf("I am here"); break; } buffer[ret] = '\0'; pc.printf("Received %d chars from server:\n%s\n", ret, buffer); } sock.close(); eth.disconnect(); while(1) {} }