MQTT client test with W5200 ethernet shield

Dependents:   IBMIoTClientEthernetExample_W5200

Fork of W5500Interface by W5500-Ethernet-Interface Makers

Committer:
Bongjun
Date:
Wed Aug 20 00:28:37 2014 +0000
Revision:
0:e11e8793c3ce
first release.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Bongjun 0:e11e8793c3ce 1 /* Copyright (C) 2012 mbed.org, MIT License
Bongjun 0:e11e8793c3ce 2 *
Bongjun 0:e11e8793c3ce 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
Bongjun 0:e11e8793c3ce 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
Bongjun 0:e11e8793c3ce 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
Bongjun 0:e11e8793c3ce 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
Bongjun 0:e11e8793c3ce 7 * furnished to do so, subject to the following conditions:
Bongjun 0:e11e8793c3ce 8 *
Bongjun 0:e11e8793c3ce 9 * The above copyright notice and this permission notice shall be included in all copies or
Bongjun 0:e11e8793c3ce 10 * substantial portions of the Software.
Bongjun 0:e11e8793c3ce 11 *
Bongjun 0:e11e8793c3ce 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
Bongjun 0:e11e8793c3ce 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Bongjun 0:e11e8793c3ce 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
Bongjun 0:e11e8793c3ce 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Bongjun 0:e11e8793c3ce 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Bongjun 0:e11e8793c3ce 17 */
Bongjun 0:e11e8793c3ce 18
Bongjun 0:e11e8793c3ce 19 #ifndef UDPSOCKET_H
Bongjun 0:e11e8793c3ce 20 #define UDPSOCKET_H
Bongjun 0:e11e8793c3ce 21
Bongjun 0:e11e8793c3ce 22 #include "Socket/Socket.h"
Bongjun 0:e11e8793c3ce 23 #include "Socket/Endpoint.h"
Bongjun 0:e11e8793c3ce 24
Bongjun 0:e11e8793c3ce 25 /**
Bongjun 0:e11e8793c3ce 26 UDP Socket
Bongjun 0:e11e8793c3ce 27 */
Bongjun 0:e11e8793c3ce 28 class UDPSocket: public Socket
Bongjun 0:e11e8793c3ce 29 {
Bongjun 0:e11e8793c3ce 30
Bongjun 0:e11e8793c3ce 31 public:
Bongjun 0:e11e8793c3ce 32 /** Instantiate an UDP Socket.
Bongjun 0:e11e8793c3ce 33 */
Bongjun 0:e11e8793c3ce 34 UDPSocket();
Bongjun 0:e11e8793c3ce 35
Bongjun 0:e11e8793c3ce 36 /** Init the UDP Client Socket without binding it to any specific port
Bongjun 0:e11e8793c3ce 37 \return 0 on success, -1 on failure.
Bongjun 0:e11e8793c3ce 38 */
Bongjun 0:e11e8793c3ce 39 int init(void);
Bongjun 0:e11e8793c3ce 40
Bongjun 0:e11e8793c3ce 41 /** Bind a UDP Server Socket to a specific port
Bongjun 0:e11e8793c3ce 42 \param port The port to listen for incoming connections on
Bongjun 0:e11e8793c3ce 43 \return 0 on success, -1 on failure.
Bongjun 0:e11e8793c3ce 44 */
Bongjun 0:e11e8793c3ce 45 int bind(int port = -1);
Bongjun 0:e11e8793c3ce 46
Bongjun 0:e11e8793c3ce 47 /** Send a packet to a remote endpoint
Bongjun 0:e11e8793c3ce 48 \param remote The remote endpoint
Bongjun 0:e11e8793c3ce 49 \param packet The packet to be sent
Bongjun 0:e11e8793c3ce 50 \param length The length of the packet to be sent
Bongjun 0:e11e8793c3ce 51 \return the number of written bytes on success (>=0) or -1 on failure
Bongjun 0:e11e8793c3ce 52 */
Bongjun 0:e11e8793c3ce 53 int sendTo(Endpoint &remote, char *packet, int length);
Bongjun 0:e11e8793c3ce 54
Bongjun 0:e11e8793c3ce 55 /** Receive a packet from a remote endpoint
Bongjun 0:e11e8793c3ce 56 \param remote The remote endpoint
Bongjun 0:e11e8793c3ce 57 \param buffer The buffer for storing the incoming packet data. If a packet
Bongjun 0:e11e8793c3ce 58 is too long to fit in the supplied buffer, excess bytes are discarded
Bongjun 0:e11e8793c3ce 59 \param length The length of the buffer
Bongjun 0:e11e8793c3ce 60 \return the number of received bytes on success (>=0) or -1 on failure
Bongjun 0:e11e8793c3ce 61 */
Bongjun 0:e11e8793c3ce 62 int receiveFrom(Endpoint &remote, char *buffer, int length);
Bongjun 0:e11e8793c3ce 63
Bongjun 0:e11e8793c3ce 64 private:
Bongjun 0:e11e8793c3ce 65 void confEndpoint(Endpoint & ep);
Bongjun 0:e11e8793c3ce 66 void readEndpoint(Endpoint & ep, uint8_t info[]);
Bongjun 0:e11e8793c3ce 67 };
Bongjun 0:e11e8793c3ce 68
Bongjun 0:e11e8793c3ce 69 #endif