M3 Board Socket Communication

Dependencies:   EthernetInterface mbed-rtos mbed

Fork of TCPEchoServer by Mbed

Revision:
8:6db0cbf4761a
Parent:
7:a5ead1402704
--- a/main.cpp	Mon May 04 22:47:02 2015 +0000
+++ b/main.cpp	Thu Jun 16 16:51:46 2016 +0000
@@ -1,7 +1,10 @@
 #include "mbed.h"
 #include "EthernetInterface.h"
+#include "string.h"
 
-#define ECHO_SERVER_PORT   7
+DigitalOut led1(LED1);
+
+#define ECHO_SERVER_PORT   9050
 
 int main (void) {
     EthernetInterface eth;
@@ -17,7 +20,7 @@
         printf("\nWait for new connection...\n");
         TCPSocketConnection client;
         server.accept(client);
-        client.set_blocking(false, 1500); // Timeout after (1.5)s
+        //client.set_blocking(false, 1500); // Timeout after (1.5)s
         
         printf("Connection from: %s\n", client.get_address());
         char buffer[256];
@@ -29,16 +32,21 @@
             buffer[n] = '\0';
             printf("Received message from Client :'%s'\n",buffer);
             
+            if(strstr(buffer, "On1"))
+                led1 = 1;
+            if(strstr(buffer, "Off1"))
+                led1 = 0;
+            
             // reverse the message
-            char temp;
+            /*char temp;
             for(int f = 0, l = n-1; f<l; f++,l--){
                 temp = buffer[f];
                 buffer[f] = buffer[l];
                 buffer[l] = temp;
                 }
-            
+            */
             // print reversed message to terminal
-            printf("Sending message to Client: '%s'\n",buffer);
+            printf("Sending message to Client: '%s'\n","OK");
             
             // Echo received message back to client
             client.send_all(buffer, n);