An API for using MQTT over multiple transports
Dependencies: FP MQTTPacket
Dependents: IBMIoTClientEthernetExample_W5500 IBMIoTClientEthernetExample_W5200
Fork of MQTT by
Diff: MQTTSocket.h
- 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