TCP Echo Client example

Dependencies:   EthernetInterface mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
emilmont
Date:
Thu Jul 26 10:10:48 2012 +0000
Parent:
0:e8f884c94549
Child:
2:563aa530f0dd
Commit message:
First implementation

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
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Thu Jul 26 10:10:48 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/EthernetInterface/#56438e188f04
--- a/main.cpp	Thu Jul 26 10:04:15 2012 +0000
+++ b/main.cpp	Thu Jul 26 10:10:48 2012 +0000
@@ -1,1 +1,31 @@
 #include "mbed.h"
+#include "EthernetInterface.h"
+
+const char* ECHO_SERVER_ADDRESS = "10.2.131.73";
+const int ECHO_PORT = 7;
+
+int main() {
+    EthernetInterface eth;
+    eth.init(); //Use DHCP
+    eth.connect();
+    printf("IP Address is %s\n", eth.getIPAddress());
+    
+    TCPSocketConnection sock;
+    while (sock.connect(ECHO_SERVER_ADDRESS, ECHO_PORT) < 0) {
+        printf("Unable to connect to (%s) on port (%d)\n", ECHO_SERVER_ADDRESS, ECHO_PORT);
+        wait(1);
+    }
+    
+    char hello[] = "Hello World\n";
+    sock.send_all(hello, sizeof(hello) - 1);
+    
+    char buf[256];
+    int n = sock.receive(buf, 256);
+    // buf[n] = '\0';
+    printf("%s", buf);
+    
+    sock.close();
+    eth.disconnect();
+    
+    while(true) {}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Thu Jul 26 10:10:48 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#4238c328365e