Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: C12832_lcd EthernetInterface USBHost mbed-rtos mbed wave_player
src/main.cpp@0:6a2537e4188b, 2014-01-07 (annotated)
- Committer:
- aos
- Date:
- Tue Jan 07 04:15:05 2014 +0000
- Revision:
- 0:6a2537e4188b
- Child:
- 1:3b567aa3b09e
Created
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| aos | 0:6a2537e4188b | 1 | #include "mbed.h" |
| aos | 0:6a2537e4188b | 2 | #include "EthernetInterface.h" |
| aos | 0:6a2537e4188b | 3 | |
| aos | 0:6a2537e4188b | 4 | int main() { |
| aos | 0:6a2537e4188b | 5 | EthernetInterface eth; |
| aos | 0:6a2537e4188b | 6 | eth.init(); //Use DHCP |
| aos | 0:6a2537e4188b | 7 | eth.connect(); |
| aos | 0:6a2537e4188b | 8 | printf("IP Address is %s\n", eth.getIPAddress()); |
| aos | 0:6a2537e4188b | 9 | |
| aos | 0:6a2537e4188b | 10 | TCPSocketConnection sock; |
| aos | 0:6a2537e4188b | 11 | sock.connect("mbed.org", 80); |
| aos | 0:6a2537e4188b | 12 | |
| aos | 0:6a2537e4188b | 13 | char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n"; |
| aos | 0:6a2537e4188b | 14 | sock.send_all(http_cmd, sizeof(http_cmd)-1); |
| aos | 0:6a2537e4188b | 15 | |
| aos | 0:6a2537e4188b | 16 | char buffer[300]; |
| aos | 0:6a2537e4188b | 17 | int ret; |
| aos | 0:6a2537e4188b | 18 | while (true) { |
| aos | 0:6a2537e4188b | 19 | ret = sock.receive(buffer, sizeof(buffer)-1); |
| aos | 0:6a2537e4188b | 20 | if (ret <= 0) |
| aos | 0:6a2537e4188b | 21 | break; |
| aos | 0:6a2537e4188b | 22 | buffer[ret] = '\0'; |
| aos | 0:6a2537e4188b | 23 | printf("Received %d chars from server:\n%s\n", ret, buffer); |
| aos | 0:6a2537e4188b | 24 | } |
| aos | 0:6a2537e4188b | 25 | |
| aos | 0:6a2537e4188b | 26 | sock.close(); |
| aos | 0:6a2537e4188b | 27 | |
| aos | 0:6a2537e4188b | 28 | eth.disconnect(); |
| aos | 0:6a2537e4188b | 29 | |
| aos | 0:6a2537e4188b | 30 | while(1) {} |
| aos | 0:6a2537e4188b | 31 | } |