TCP Server

Dependencies:   EthernetInterface mbed-rtos mbed

Fork of TCPEchoServer by mbed official

Files at this revision

API Documentation at this revision

Comitter:
saragbolivar
Date:
Mon Jul 07 19:26:10 2014 +0000
Parent:
6:5dae237341f7
Commit message:
TCPEchoServer

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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/EthernetInterface.lib	Tue Jun 04 16:07:06 2013 +0100
+++ b/EthernetInterface.lib	Mon Jul 07 19:26:10 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/EthernetInterface/
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/EthernetInterface/#f6ec7a025939
--- a/main.cpp	Tue Jun 04 16:07:06 2013 +0100
+++ b/main.cpp	Mon Jul 07 19:26:10 2014 +0000
@@ -2,33 +2,45 @@
 #include "EthernetInterface.h"
 
 #define ECHO_SERVER_PORT   7
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
+int x;
 
 int main (void) {
     EthernetInterface eth;
     eth.init(); //Use DHCP
     eth.connect();
-    printf("IP Address is %s\n", eth.getIPAddress());
+    printf("IP Address is %s\n\r", eth.getIPAddress());
     
     TCPSocketServer server;
-    server.bind(ECHO_SERVER_PORT);
+    server.bind(9999);
     server.listen();
     
     while (true) {
-        printf("\nWait for new connection...\n");
+        printf("Wait 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];
-        while (true) {
-            int n = client.receive(buffer, sizeof(buffer));
-            if (n <= 0) break;
-            
-            client.send_all(buffer, n);
-            if (n <= 0) break;
-        }
-        
+        char buffer[1];
+        while (true) 
+        {
+            printf("%s",buffer);
+            if(client.send(buffer, sizeof(buffer)))
+            {
+                led1=1;
+                wait(1);
+                led1=0;   
+            }
+                
+                int n = client.receive(buffer, sizeof(buffer));
+                if (n <= 0) break;
+                client.send_all(buffer, n);
+                if (n <= 0) break;
+        }   
         client.close();
     }
 }
--- a/mbed-rtos.lib	Tue Jun 04 16:07:06 2013 +0100
+++ b/mbed-rtos.lib	Mon Jul 07 19:26:10 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed-rtos/
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed-rtos/#be2573f85b81
--- a/mbed.bld	Tue Jun 04 16:07:06 2013 +0100
+++ b/mbed.bld	Mon Jul 07 19:26:10 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/8a40adfe8776
\ No newline at end of file