MQTT for Eth, Wifi, GPRS

Dependencies:   FP MQTTPacket

Dependents:   PB_Emma_Ethernet

Fork of MQTT by W5500-Ethernet-Interface Makers

Revision:
44:f53a95f9c1d8
Parent:
36:2f1ada427e56
--- a/MQTTSocket.h	Fri Sep 26 08:04:47 2014 +0000
+++ b/MQTTSocket.h	Mon Sep 29 04:56:42 2014 +0000
@@ -6,36 +6,45 @@
 
 class MQTTSocket
 {
-public:    
+public:                        
+    ~MQTTSocket()
+    {   
+        if(mysock)
+            delete mysock;
+    }   
+
     int connect(char* hostname, int port, int timeout=1000)
-    {
-        mysock.set_blocking(false, timeout);    // 1 second Timeout 
-        return mysock.connect(hostname, port);
-    }
+    {   
+        mysock->set_blocking(false, timeout);    // 1 second Timeout
+        return mysock->connect(hostname, port);
+    }   
 
     int read(unsigned char* buffer, int len, int timeout)
-    {
-        mysock.set_blocking(false, timeout);  
-        return mysock.receive((char*)buffer, len);
-    }
-    
+    {   
+        mysock->set_blocking(false, timeout);
+        return mysock->receive((char*)buffer, len);
+    }   
+        
     int write(unsigned char* buffer, int len, int timeout)
-    {
-        mysock.set_blocking(false, timeout);  
-        return mysock.send((char*)buffer, len);
-    }
-    
+    {   
+        mysock->set_blocking(false, timeout);
+        return mysock->send((char*)buffer, len);
+    }   
+        
     int disconnect()
-    {
-        return mysock.close();
-    }
-    
+    {   
+        return mysock->close();
+    }   
+           
+protected:
+    void createSocket() { mysock = new TCPSocketConnection(); }
+
 private:
 
-    TCPSocketConnection mysock; 
-    
+    TCPSocketConnection *mysock;
+        
 };
 
 
 
-#endif
+#endif
\ No newline at end of file