Index: rtos_arduino/trunk/arduino_lib/libraries/ESP8266_Arudino_AT/Client_ESP8266.h
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/ESP8266_Arudino_AT/Client_ESP8266.h	(revision 211)
+++ rtos_arduino/trunk/arduino_lib/libraries/ESP8266_Arudino_AT/Client_ESP8266.h	(revision 212)
@@ -23,9 +23,17 @@
 #include "Client.h"
 
-class ESP8266Client: public Client, public ESP8266 {
+class ESP8266Client: public Client {
   public:
     ESP8266Client(void) {
-        pbuffer = &rx_buffer[0];
+        mux_id = 0;
+        mux = false; 
+        pbuffer = &(WiFi.rx_buffer[0]);
     }
+
+    ESP8266Client(uint8_t _mux_id) {
+        mux_id = _mux_id;
+        mux = true; 
+        pbuffer = &(WiFi.rx_buffer[mux_id]);
+    }    
     
     /*
@@ -34,59 +42,139 @@
      */
     int connect(IPAddress ip, uint16_t port) {
-        if (isConnected()) return 1;
-        String ip_str;
-        ip_str.concat(ip[0]); ip_str.concat(".");
-        ip_str.concat(ip[1]); ip_str.concat(".");
-        ip_str.concat(ip[2]); ip_str.concat(".");
-        ip_str.concat(ip[3]);
-        return (createTCP(ip_str, port))? 1 : 0;
+        if (mux) {
+            if (WiFi.isConnected(mux_id)) return 1;
+            String ip_str;
+            ip_str.concat(ip[0]); ip_str.concat(".");
+            ip_str.concat(ip[1]); ip_str.concat(".");
+            ip_str.concat(ip[2]); ip_str.concat(".");
+            ip_str.concat(ip[3]);
+            return (WiFi.createTCP(mux_id, ip_str, port))? 1 : 0;            
+        }
+        else {
+            if (WiFi.isConnected()) return 1;
+            String ip_str;
+            ip_str.concat(ip[0]); ip_str.concat(".");
+            ip_str.concat(ip[1]); ip_str.concat(".");
+            ip_str.concat(ip[2]); ip_str.concat(".");
+            ip_str.concat(ip[3]);
+            return (WiFi.createTCP(ip_str, port))? 1 : 0;
+        }
     };
     
     int connect(const char *host, uint16_t port) {
-        if (isConnected()) return 1;
-        String ip_str(host);
-        return (createTCP(ip_str, port))? 1 : 0;
+        if (mux) {
+            if (WiFi.isConnected(mux_id)) return 1;
+            String ip_str(host);
+            return (WiFi.createTCP(mux_id, ip_str, port))? 1 : 0;
+        }
+        else {
+            if (WiFi.isConnected()) return 1;
+            String ip_str(host);
+            return (WiFi.createTCP(ip_str, port))? 1 : 0;
+        }
     };
     
     size_t write(uint8_t data) {
-        if(send(&data, 1)){
-            return 1;
-        }        
-        return 0;
+        if (mux) {
+            if(WiFi.send(mux_id, &data, 1)){
+                return 1;
+            }        
+            return 0;
+        }
+        else {
+            if(WiFi.send(&data, 1)){
+                return 1;
+            }        
+            return 0;
+        }
     };
 
     size_t write(const uint8_t *buf, size_t size){
-        if(send(buf, size)){
-            return size;
+        if (mux) {
+            if(WiFi.send(mux_id, buf, size)){
+                return size;
+            }
+            return 0;
         }
-        return 0;
+        else {
+            if(WiFi.send(buf, size)){
+                return size;
+            }
+            return 0;            
+        }
     };
     
-    int available(){
-        return isDataAvailable();
+    int available(void){
+        if(mux) {
+            return WiFi.isDataAvailable(mux_id);
+        }
+        else {
+            return WiFi.isDataAvailable();
+        }
     };
     
     int read(){
         uint8_t data;
-        if(recv(&data, 1) == 1) {
-            return data;
+        if(mux) {
+            if(WiFi.recv(mux_id, &data, 1) == 1) {
+                return data;
+            }
+            return (int)-1;            
         }
-        return (int)-1;
+        else {
+            if(WiFi.recv(&data, 1) == 1) {
+                return data;
+            }
+            return (int)-1;
+        }
     };
     
     int read(uint8_t *buf, size_t size){
-        return recv(buf, size);
+        if(mux) {
+            return WiFi.recv(mux_id, buf, size);
+        }
+        else {
+            return WiFi.recv(buf, size);
+        }
     };
     
-    int peek(){
+    int peek(void){
         return pbuffer->peek();
     };
     
-    void flush(){};
-    void stop(){ if (isConnected()) { releaseTCP(); }}
-    uint8_t connected(){return (isConnected())? 1 : 0;};
-    operator bool(){return isConnected();};
+    void flush(void){};
+    void stop(void){
+        if(mux) {
+            if (WiFi.isConnected(mux_id)) {
+                WiFi.releaseTCP(mux_id);
+            }            
+        }
+        else {
+            if (WiFi.isConnected()) {
+                WiFi.releaseTCP();
+            }
+        }
+    };
+    uint8_t connected(void){
+        if(mux) {
+            return (WiFi.isConnected(mux_id))? 1 : 0;
+        }
+        else {
+            return (WiFi.isConnected())? 1 : 0;
+        }
+    };
+    operator bool(){
+        if(mux) {
+            return WiFi.isConnected(mux_id);
+        }
+        else {
+            return WiFi.isConnected();
+        }
+    };
+
   private:
     ESP8266_RingBuffer *pbuffer;
+    uint8_t mux_id;
+    bool    mux;
 };
 
Index: rtos_arduino/trunk/arduino_lib/libraries/ESP8266_Arudino_AT/ESP8266.cpp
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/ESP8266_Arudino_AT/ESP8266.cpp	(revision 211)
+++ rtos_arduino/trunk/arduino_lib/libraries/ESP8266_Arudino_AT/ESP8266.cpp	(revision 212)
@@ -1293,2 +1293,3 @@
 }
 
+ESP8266 WiFi;
Index: rtos_arduino/trunk/arduino_lib/libraries/ESP8266_Arudino_AT/ESP8266.h
===================================================================
--- rtos_arduino/trunk/arduino_lib/libraries/ESP8266_Arudino_AT/ESP8266.h	(revision 211)
+++ rtos_arduino/trunk/arduino_lib/libraries/ESP8266_Arudino_AT/ESP8266.h	(revision 212)
@@ -487,4 +487,6 @@
      */    
     bool getMuxCStatus(uint8_t *mux_id_ptn);
+
+    friend class ESP8266Client;
     
  private:
@@ -594,4 +596,6 @@
 };
 
+extern ESP8266 WiFi;
+
 #endif /* #ifndef __ESP8266_H__ */
 
