Zoltan Hudak / Mbed OS MQTT_Hello

Dependencies:   ENC28J60-EMAC

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MQTTNetwork.h Source File

MQTTNetwork.h

00001 #ifndef _MQTTNETWORK_H_
00002 #define _MQTTNETWORK_H_
00003 
00004 #include "EthernetInterface.h"
00005 #include "TCPSocket.h"
00006 
00007 class   MQTTNetwork
00008 {
00009 public:
00010     MQTTNetwork(EthernetInterface* aNetwork) :
00011     network(aNetwork),
00012     socket(new TCPSocket)
00013     {}
00014 
00015     ~   MQTTNetwork()                                       { delete socket; }
00016     int read(unsigned char* buffer, int len, int timeout)   { return socket->recv(buffer, len); }
00017     int write(unsigned char* buffer, int len, int timeout)  { return socket->send(buffer, len); }
00018     int connect(const char* hostname, uint16_t port)
00019     {
00020         SocketAddress   addr;
00021 
00022         socket->open(network);
00023         addr.set_ip_address(hostname);
00024         addr.set_port(port);
00025         return socket->connect(addr);
00026     }
00027     int disconnect()    { return socket->close(); }
00028 private:
00029     EthernetInterface*  network;
00030     TCPSocket*          socket;
00031 };
00032 #endif // _MQTTNETWORK_H_