![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
TCP client mbed RTOS
Dependencies: mbed LM75B mbed-rtos EthernetInterface
main.cpp
- Committer:
- emilmont
- Date:
- 2012-08-10
- Revision:
- 11:59dcefdda506
- Parent:
- 9:4757a976148d
- Child:
- 15:954b6cd3d853
File content as of revision 11:59dcefdda506:
#include "mbed.h" #include "EthernetInterface.h" int main() { EthernetInterface eth; eth.init(); //Use DHCP eth.connect(); 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) break; buffer[ret] = '\0'; printf("Received %d chars from server:\n%s\n", ret, buffer); } sock.close(); eth.disconnect(); while(1) {} }