Index: /rtos_arduino/trunk/examples/WifiEcho/rca_app.cpp
===================================================================
--- /rtos_arduino/trunk/examples/WifiEcho/rca_app.cpp	(revision 199)
+++ /rtos_arduino/trunk/examples/WifiEcho/rca_app.cpp	(revision 200)
@@ -1,3 +1,4 @@
 #include "rca.h"
+#include "ESP8266.h"
 
 #define SSID       ""
@@ -9,7 +10,9 @@
 #define WMODE_STATION
 
-#include "ESP8266.h"
-
 ESP8266 wifi;
+
+#ifdef MULTI_ECHO_SERVER
+bool setup_done = false;
+#endif /* MULTI_ECHO_SERVER */
 
 void setup()
@@ -80,6 +83,6 @@
     }
 
-    if (wifi.setTCPServerTimeout(10)) { 
-        Serial.print("set tcp server timout 10 seconds\r\n");
+    if (wifi.setTCPServerTimeout(60)) { 
+        Serial.print("set tcp server timout 60 seconds\r\n");
     } else {
         Serial.print("set tcp server timout err\r\n");
@@ -87,49 +90,139 @@
 
     Serial.print("setup end\r\n");
-}
+
+#ifdef MULTI_ECHO_SERVER
+    setup_done = true;
+#endif /* MULTI_ECHO_SERVER */    
+}
+
+#define MUX_NULL 0xff
 
 uint8_t mux_id_ptn;
+
+uint8_t mux_id = MUX_NULL;
+uint8_t task1_mux_id = MUX_NULL;
 
 void loop()
 {
-    uint8_t mux_id;
     uint8_t buffer[128] = {0};
-    uint8_t pre_mux_id_ptn;
-    uint32_t len
-      
+    uint8_t pre_mux_id_ptn;    
+    uint32_t len;
+    uint32_t i;
+
+    delay(1);    
+    /* Check Connection Status */
     pre_mux_id_ptn = mux_id_ptn;
 
     if(!wifi.getMuxCStatus(&mux_id_ptn)) {
-        Serial.println("isConnected(&mux_id_ptn) : Error!");
-        while(1);
-    }
-    
-    if (pre_mux_id_ptn != mux_id_ptn) {
-        Serial.print("Connection Status changed! : 0x");
-        Serial.println(mux_id_ptn, HEX);
-    }
-
-    if(!wifi.isDataAvailable()) {
-        return;
-    }
-      
-    if((len = wifi.recv(&mux_id, buffer, sizeof(buffer))) == 0) {
-        return;
-    }
-
-    String cmd = (char*)buffer;
-    
-    Serial.print("Web Server Task : Recive Request from mux : ");
+        Serial.println("getMuxCStatus(&mux_id_ptn) : Error!");
+    }
+    else {        
+        if (pre_mux_id_ptn != mux_id_ptn) {
+            Serial.print("Connection Status changed! : 0x");
+            Serial.println(mux_id_ptn, HEX);
+            if (mux_id_ptn & 0x01) {
+                mux_id = 0; 
+            }
+            if (mux_id_ptn & 0x02) {
+                task1_mux_id = 1;
+            }
+        }
+    }
+
+    if (mux_id == MUX_NULL) {
+        return;
+    }
+    
+    if (!wifi.isConnected(mux_id)) {
+        Serial.print("Echo Server : Port is closed: ");
+        Serial.println(mux_id);
+        mux_id = MUX_NULL;
+        return;
+    }
+    
+    if((len = wifi.recv(mux_id, buffer, sizeof(buffer))) == 0) {
+        return;
+    }
+
+    /* Recived Data */
+
+    for(i = 0; i < len; i++) {
+        /* If Recive Ctrl-q(17) */
+        if(buffer[i] == 17) {
+            Serial.print("Echo Server : Close port : ");
+            Serial.println(mux_id);            
+            wifi.releaseTCP(mux_id);
+            mux_id = MUX_NULL;
+            return;
+        }
+    }
+
+    Serial.print("Echo Server : Recive Data from mux : ");
     Serial.println(mux_id);
-    Serial.print("Web Server Task : Recive len   : ");
+    Serial.print("Echo Server : Recive len   : ");
     Serial.println(len);
-    Serial.print("Web Server Task : Recive Data  : ");
-    Serial.println(cmd);    
-    
-    if(!wifi.send(mux_id, cmd)) {
-        Serial.println("send(mux_id, cmd) : Error!");
-        while(1);
-    }
-    
-    wifi.releaseTCP(mux_id);
-}
+    Serial.print("Echo Server : Recive Data  : ");
+    Serial.println((char*)buffer);
+    
+    if(!wifi.send(mux_id, buffer, len)) {
+        Serial.println("Echo Server : send(mux_id, cmd) : Error!");
+    }
+}
+
+#ifdef MULTI_ECHO_SERVER
+/*
+ *  For TASK1
+ */
+void task1_setup() {
+    while(!setup_done) {
+        delay(1);
+    }
+    Serial.println("Echo Server Task1 : start");
+}
+
+void task1_loop() {
+    uint8_t buffer[128] = {0};
+    uint32_t len;
+    uint32_t i;
+
+    if (task1_mux_id == MUX_NULL) {
+        delay(1);
+        return;
+    }
+    
+    if (!wifi.isConnected(task1_mux_id)) {
+        Serial.print("Echo Server Task1 : Port is closed: ");
+        Serial.println(task1_mux_id);
+        task1_mux_id = MUX_NULL;
+        return;
+    }
+    if((len = wifi.recv(task1_mux_id, buffer, sizeof(buffer))) == 0) {
+        return;
+    }        
+
+    /* Recived Data */
+
+    for(i = 0; i < len; i++) {
+        /* If Recive Ctrl-q(17) */
+        if(buffer[i] == 17) {
+            Serial.print("Echo Server Task1 : Close port : ");
+            Serial.println(task1_mux_id);            
+            wifi.releaseTCP(task1_mux_id);
+            task1_mux_id = MUX_NULL;
+            return;
+        }
+    }
+
+    Serial.print("Echo Server Task1 : Recive Data from mux : ");
+    Serial.println(task1_mux_id);
+    Serial.print("Echo Server Task1 : Recive len   : ");
+    Serial.println(len);
+    Serial.print("Echo Server Task1 : Recive Data  : ");
+    Serial.println((char*)buffer);
+    
+    if(!wifi.send(task1_mux_id, buffer, len)) {
+        Serial.println("Echo Server Task1 : send(task1_mux_id, cmd) : Error!");
+    }
+    delay(1);    
+}
+#endif /* MULTI_ECHO_SERVER */
Index: /rtos_arduino/trunk/examples/WifiEcho/rca_app.h
===================================================================
--- /rtos_arduino/trunk/examples/WifiEcho/rca_app.h	(revision 199)
+++ /rtos_arduino/trunk/examples/WifiEcho/rca_app.h	(revision 200)
@@ -2,18 +2,11 @@
 #define _RCA_APP_H_
 
+#define MULTI_ECHO_SERVER
+
+#ifndef MULTI_ECHO_SERVER
 #define RCA_NUM_TASK 0
-
-/*
- *  Use Serial3
- */
-#define RCA_USE_SERIAL3
-
-#define  RCA_TASK2_LOOP_PRI  4 //Web
-#define  RCA_TASK3_LOOP_PRI  3 //LED
-#define  RCA_TASK4_LOOP_PRI  7 //TFT
-#define  RCA_TASK5_LOOP_PRI  6 //Processing
-
-#define RCA_ENABLE_PROFILING
-#define RCA_PROFILING_CYC_MS  1
+#else /* MULTI_ECHO_SERVER */
+#define RCA_NUM_TASK 1
+#endif /* MULTI_ECHO_SERVER */
 
 #endif /* _RCA_APP_H_ */
