MQTT For Wiz750sr

Dependencies:   FP MQTTPacket

Fork of MQTT by Albin Sebastian

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MQTTSocket.h Source File

MQTTSocket.h

00001 #if !defined(MQTTSOCKET_H)
00002 #define MQTTSOCKET_H
00003 
00004 #include "MQTTmbed.h"
00005 #include "TCPSocketConnection.h"
00006 
00007 class MQTTSocket
00008 {
00009 public: 
00010     ~MQTTSocket()
00011     {   
00012         if(mysock)
00013             delete mysock;
00014     }  
00015       
00016     int connect(char* hostname, int port, int timeout=1000)
00017     {
00018         mysock->set_timeout(timeout);
00019         mysock->set_blocking(false, timeout);    // 1 second Timeout 
00020         return mysock->connect(hostname, port);
00021     }
00022 
00023     int read(unsigned char* buffer, int len, int timeout)
00024     {
00025         mysock->set_blocking(false, timeout);  
00026         return mysock->receive((char*)buffer, len);
00027     }
00028     
00029     int write(unsigned char* buffer, int len, int timeout)
00030     {
00031         mysock->set_blocking(false, timeout);  
00032         return mysock->send((char*)buffer, len);
00033     }
00034     
00035     int disconnect()
00036     {
00037         return mysock->close();
00038     }
00039 
00040 protected:
00041     void createSocket() { mysock = new TCPSocketConnection(); }
00042 private:
00043 
00044     TCPSocketConnection *mysock; 
00045     
00046 };
00047 
00048 
00049 
00050 #endif