Fork of mbed official TCPSocket_Helloworld using PicoTCP
Dependencies: PicoTCP lpc1768-picotcp-eth mbed-rtos mbed
Fork of TCPSocket_HelloWorld by
This is a fork of the official TCPSocket_Helloworld from mbed. (https://mbed.org/users/mbed_official/code/TCPSocket_HelloWorld/).
This project demonstrates that the PicoTCP library basically provides the same API calls, so in order to change the TCP/IP stack of your application, you only need to remove the EthernetInterface library and replace it with the following two projects:
main.cpp@15:e996dc0de6c5, 2013-07-03 (annotated)
- Committer:
- tass
- Date:
- Wed Jul 03 09:13:29 2013 +0000
- Revision:
- 15:e996dc0de6c5
- Parent:
- 11:59dcefdda506
Updated to the latest revisions for PicoTCP and lpc1768-picotcp-eth/
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
donatien | 0:bb128f0e952f | 1 | #include "mbed.h" |
donatien | 0:bb128f0e952f | 2 | #include "EthernetInterface.h" |
donatien | 0:bb128f0e952f | 3 | |
emilmont | 7:65188f4a8c25 | 4 | int main() { |
donatien | 0:bb128f0e952f | 5 | EthernetInterface eth; |
donatien | 0:bb128f0e952f | 6 | eth.init(); //Use DHCP |
donatien | 0:bb128f0e952f | 7 | eth.connect(); |
emilmont | 2:e087e9b789e9 | 8 | printf("IP Address is %s\n", eth.getIPAddress()); |
donatien | 0:bb128f0e952f | 9 | |
emilmont | 7:65188f4a8c25 | 10 | TCPSocketConnection sock; |
donatien | 0:bb128f0e952f | 11 | sock.connect("mbed.org", 80); |
donatien | 0:bb128f0e952f | 12 | |
emilmont | 9:4757a976148d | 13 | char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n"; |
emilmont | 11:59dcefdda506 | 14 | sock.send_all(http_cmd, sizeof(http_cmd)-1); |
emilmont | 7:65188f4a8c25 | 15 | |
emilmont | 9:4757a976148d | 16 | char buffer[300]; |
donatien | 0:bb128f0e952f | 17 | int ret; |
emilmont | 7:65188f4a8c25 | 18 | while (true) { |
emilmont | 9:4757a976148d | 19 | ret = sock.receive(buffer, sizeof(buffer)-1); |
emilmont | 7:65188f4a8c25 | 20 | if (ret <= 0) |
emilmont | 7:65188f4a8c25 | 21 | break; |
emilmont | 9:4757a976148d | 22 | buffer[ret] = '\0'; |
emilmont | 9:4757a976148d | 23 | printf("Received %d chars from server:\n%s\n", ret, buffer); |
emilmont | 7:65188f4a8c25 | 24 | } |
donatien | 0:bb128f0e952f | 25 | |
emilmont | 7:65188f4a8c25 | 26 | sock.close(); |
donatien | 0:bb128f0e952f | 27 | |
emilmont | 7:65188f4a8c25 | 28 | eth.disconnect(); |
donatien | 5:01f6c3e112af | 29 | |
emilmont | 9:4757a976148d | 30 | while(1) {} |
donatien | 0:bb128f0e952f | 31 | } |