Host library for controlling a WiConnect enabled Wi-Fi module.

Dependents:   wiconnect-ota_example wiconnect-web_setup_example wiconnect-test-console wiconnect-tcp_server_example ... more

Committer:
aymangrais
Date:
Mon Sep 28 03:38:43 2015 +0000
Revision:
42:8ffb253b09e7
Parent:
29:b6af04b77a56
increase ota timeout to be 5 seconds (instead of 1.5 sec)

Who changed what in which revision?

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