Contains example code to connect the mbed LPC1768 or FRDM-K64F devices to the IBM Internet of Things Cloud service via ethernet.

Dependencies:   C12832 MQTT LM75B MMA7660

Dependents:   MFT_IoT_demo_USB400 IBM_RFID

Committer:
samdanbury
Date:
Wed Aug 20 12:45:14 2014 +0000
Revision:
6:37b6d0d56190
Code completely changed to improve the structure, flow and memory usage of the application

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samdanbury 6:37b6d0d56190 1 /* Copyright (C) 2012 mbed.org, MIT License
samdanbury 6:37b6d0d56190 2 *
samdanbury 6:37b6d0d56190 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
samdanbury 6:37b6d0d56190 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
samdanbury 6:37b6d0d56190 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
samdanbury 6:37b6d0d56190 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
samdanbury 6:37b6d0d56190 7 * furnished to do so, subject to the following conditions:
samdanbury 6:37b6d0d56190 8 *
samdanbury 6:37b6d0d56190 9 * The above copyright notice and this permission notice shall be included in all copies or
samdanbury 6:37b6d0d56190 10 * substantial portions of the Software.
samdanbury 6:37b6d0d56190 11 *
samdanbury 6:37b6d0d56190 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
samdanbury 6:37b6d0d56190 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
samdanbury 6:37b6d0d56190 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
samdanbury 6:37b6d0d56190 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
samdanbury 6:37b6d0d56190 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
samdanbury 6:37b6d0d56190 17 */
samdanbury 6:37b6d0d56190 18
samdanbury 6:37b6d0d56190 19 #ifndef TCPSOCKET_H
samdanbury 6:37b6d0d56190 20 #define TCPSOCKET_H
samdanbury 6:37b6d0d56190 21
samdanbury 6:37b6d0d56190 22 #include "Socket/Socket.h"
samdanbury 6:37b6d0d56190 23 #include "Socket/Endpoint.h"
samdanbury 6:37b6d0d56190 24
samdanbury 6:37b6d0d56190 25 /**
samdanbury 6:37b6d0d56190 26 TCP socket connection
samdanbury 6:37b6d0d56190 27 */
samdanbury 6:37b6d0d56190 28 class TCPSocketConnection : public Socket, public Endpoint {
samdanbury 6:37b6d0d56190 29 friend class TCPSocketServer;
samdanbury 6:37b6d0d56190 30
samdanbury 6:37b6d0d56190 31 public:
samdanbury 6:37b6d0d56190 32 /** TCP socket connection
samdanbury 6:37b6d0d56190 33 */
samdanbury 6:37b6d0d56190 34 TCPSocketConnection();
samdanbury 6:37b6d0d56190 35
samdanbury 6:37b6d0d56190 36 /** Connects this TCP socket to the server
samdanbury 6:37b6d0d56190 37 \param host The host to connect to. It can either be an IP Address or a hostname that will be resolved with DNS.
samdanbury 6:37b6d0d56190 38 \param port The host's port to connect to.
samdanbury 6:37b6d0d56190 39 \return 0 on success, -1 on failure.
samdanbury 6:37b6d0d56190 40 */
samdanbury 6:37b6d0d56190 41 int connect(const char* host, const int port);
samdanbury 6:37b6d0d56190 42
samdanbury 6:37b6d0d56190 43 /** Check if the socket is connected
samdanbury 6:37b6d0d56190 44 \return true if connected, false otherwise.
samdanbury 6:37b6d0d56190 45 */
samdanbury 6:37b6d0d56190 46 bool is_connected(void);
samdanbury 6:37b6d0d56190 47
samdanbury 6:37b6d0d56190 48 /** Send data to the remote host.
samdanbury 6:37b6d0d56190 49 \param data The buffer to send to the host.
samdanbury 6:37b6d0d56190 50 \param length The length of the buffer to send.
samdanbury 6:37b6d0d56190 51 \return the number of written bytes on success (>=0) or -1 on failure
samdanbury 6:37b6d0d56190 52 */
samdanbury 6:37b6d0d56190 53 int send(char* data, int length);
samdanbury 6:37b6d0d56190 54
samdanbury 6:37b6d0d56190 55 /** Send all the data to the remote host.
samdanbury 6:37b6d0d56190 56 \param data The buffer to send to the host.
samdanbury 6:37b6d0d56190 57 \param length The length of the buffer to send.
samdanbury 6:37b6d0d56190 58 \return the number of written bytes on success (>=0) or -1 on failure
samdanbury 6:37b6d0d56190 59 */
samdanbury 6:37b6d0d56190 60 int send_all(char* data, int length);
samdanbury 6:37b6d0d56190 61
samdanbury 6:37b6d0d56190 62 /** Receive data from the remote host.
samdanbury 6:37b6d0d56190 63 \param data The buffer in which to store the data received from the host.
samdanbury 6:37b6d0d56190 64 \param length The maximum length of the buffer.
samdanbury 6:37b6d0d56190 65 \return the number of received bytes on success (>=0) or -1 on failure
samdanbury 6:37b6d0d56190 66 */
samdanbury 6:37b6d0d56190 67 int receive(char* data, int length);
samdanbury 6:37b6d0d56190 68
samdanbury 6:37b6d0d56190 69 /** Receive all the data from the remote host.
samdanbury 6:37b6d0d56190 70 \param data The buffer in which to store the data received from the host.
samdanbury 6:37b6d0d56190 71 \param length The maximum length of the buffer.
samdanbury 6:37b6d0d56190 72 \return the number of received bytes on success (>=0) or -1 on failure
samdanbury 6:37b6d0d56190 73 */
samdanbury 6:37b6d0d56190 74 int receive_all(char* data, int length);
samdanbury 6:37b6d0d56190 75
samdanbury 6:37b6d0d56190 76 private:
samdanbury 6:37b6d0d56190 77 bool _is_connected;
samdanbury 6:37b6d0d56190 78
samdanbury 6:37b6d0d56190 79 };
samdanbury 6:37b6d0d56190 80
samdanbury 6:37b6d0d56190 81 #endif