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:
dan_ackme
Date:
Sat Aug 23 05:57:52 2014 -0700
Revision:
20:7b67c3f94de9
Added mbed socket api

Who changed what in which revision?

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