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: EthernetInterface mbed-rtos mbed
Fork of TCPSocket_HelloWorld by
Revision 7:65188f4a8c25, committed 2012-07-25
- Comitter:
- emilmont
- Date:
- Wed Jul 25 15:00:43 2012 +0000
- Parent:
- 6:b011e8862694
- Child:
- 8:2570d35b0c47
- Commit message:
- Update EthernetInterface
Changed in this revision
| EthernetInterface.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/EthernetInterface.lib Mon Jul 23 11:53:08 2012 +0000 +++ b/EthernetInterface.lib Wed Jul 25 15:00:43 2012 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/EthernetInterface/#cec293071eed +http://mbed.org/users/mbed_official/code/EthernetInterface/#fd9597f1b81b
--- a/main.cpp Mon Jul 23 11:53:08 2012 +0000
+++ b/main.cpp Wed Jul 25 15:00:43 2012 +0000
@@ -1,34 +1,32 @@
#include "mbed.h"
#include "EthernetInterface.h"
-int main()
-{
+int main() {
EthernetInterface eth;
eth.init(); //Use DHCP
eth.connect();
printf("IP Address is %s\n", eth.getIPAddress());
- TCPSocket sock;
+ TCPSocketConnection sock;
sock.connect("mbed.org", 80);
char http_cmd[] = "GET /media/uploads/donatien/hello.txt HTTP/1.1\r\nHost: %s\r\n\r\n";
- sock.send(http_cmd, sizeof(http_cmd) - 1, 3000);
-
- char in_buf[256];
- bool firstIteration = true;
+ sock.send_all(http_cmd, sizeof(http_cmd) - 1, 3000);
+
+ char in_buf[256];
int ret;
- do
- {
- ret = sock.receive(in_buf, 255, firstIteration?3000:0);
+ while (true) {
+ ret = sock.receive(in_buf, 255, 100);
+ if (ret <= 0)
+ break;
+
in_buf[ret] = '\0';
-
printf("Received %d chars from server: %s\n", ret, in_buf);
- firstIteration = false;
- } while( ret > 0 );
+ }
- sock.close();
+ sock.close();
- eth.disconnect();
+ eth.disconnect();
while(1) {
}
