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:39:17 2014 -0700
Revision:
17:7268f365676b
Fixes and documentation updates

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dan_ackme 17:7268f365676b 1 /* Copyright (C) 2012 mbed.org, MIT License
dan_ackme 17:7268f365676b 2 *
dan_ackme 17:7268f365676b 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
dan_ackme 17:7268f365676b 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
dan_ackme 17:7268f365676b 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
dan_ackme 17:7268f365676b 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
dan_ackme 17:7268f365676b 7 * furnished to do so, subject to the following conditions:
dan_ackme 17:7268f365676b 8 *
dan_ackme 17:7268f365676b 9 * The above copyright notice and this permission notice shall be included in all copies or
dan_ackme 17:7268f365676b 10 * substantial portions of the Software.
dan_ackme 17:7268f365676b 11 *
dan_ackme 17:7268f365676b 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
dan_ackme 17:7268f365676b 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
dan_ackme 17:7268f365676b 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
dan_ackme 17:7268f365676b 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
dan_ackme 17:7268f365676b 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
dan_ackme 17:7268f365676b 17 */
dan_ackme 17:7268f365676b 18
dan_ackme 17:7268f365676b 19 #ifndef UDPSOCKET_H
dan_ackme 17:7268f365676b 20 #define UDPSOCKET_H
dan_ackme 17:7268f365676b 21
dan_ackme 17:7268f365676b 22 #include "types/Socket/Socket.h"
dan_ackme 17:7268f365676b 23 #include "types/Socket/Endpoint.h"
dan_ackme 17:7268f365676b 24
dan_ackme 17:7268f365676b 25 /**
dan_ackme 17:7268f365676b 26 UDP Socket
dan_ackme 17:7268f365676b 27 */
dan_ackme 17:7268f365676b 28 class UDPSocket : public Socket {
dan_ackme 17:7268f365676b 29
dan_ackme 17:7268f365676b 30 public:
dan_ackme 17:7268f365676b 31 /** Instantiate an UDP Socket.
dan_ackme 17:7268f365676b 32 */
dan_ackme 17:7268f365676b 33 UDPSocket(int rxBufferLen = SOCKET_API_DEFAULT_RX_BUFFER_SIZE, void *rxBuffer = NULL, int txBufferLen = SOCKET_API_DEFAULT_TX_BUFFER_SIZE, void *txBuffer = NULL);
dan_ackme 17:7268f365676b 34
dan_ackme 17:7268f365676b 35 /** Init the UDP Client Socket without binding it to any specific port
dan_ackme 17:7268f365676b 36 \return 0 on success, -1 on failure.
dan_ackme 17:7268f365676b 37 */
dan_ackme 17:7268f365676b 38 int init(void);
dan_ackme 17:7268f365676b 39
dan_ackme 17:7268f365676b 40 /** Bind a UDP Server Socket to a specific port
dan_ackme 17:7268f365676b 41 \param port The port to listen for incoming connections on
dan_ackme 17:7268f365676b 42 \return 0 on success, -1 on failure.
dan_ackme 17:7268f365676b 43 */
dan_ackme 17:7268f365676b 44 int bind(int port);
dan_ackme 17:7268f365676b 45
dan_ackme 17:7268f365676b 46 /** Join the multicast group at the given address
dan_ackme 17:7268f365676b 47 *
dan_ackme 17:7268f365676b 48 * \note This is not currently supported.
dan_ackme 17:7268f365676b 49 *
dan_ackme 17:7268f365676b 50 \param address The address of the multicast group
dan_ackme 17:7268f365676b 51 \return 0 on success, -1 on failure.
dan_ackme 17:7268f365676b 52 */
dan_ackme 17:7268f365676b 53 int join_multicast_group(const char* address);
dan_ackme 17:7268f365676b 54
dan_ackme 17:7268f365676b 55 /** Set the socket in broadcasting mode
dan_ackme 17:7268f365676b 56 *
dan_ackme 17:7268f365676b 57 * \note Broadcasting is always enabled, so this
dan_ackme 17:7268f365676b 58 * doesn't do anything useful.
dan_ackme 17:7268f365676b 59 *
dan_ackme 17:7268f365676b 60 \return 0 on success, -1 on failure.
dan_ackme 17:7268f365676b 61 */
dan_ackme 17:7268f365676b 62 int set_broadcasting(bool broadcast=true);
dan_ackme 17:7268f365676b 63
dan_ackme 17:7268f365676b 64 /** Send a packet to a remote endpoint
dan_ackme 17:7268f365676b 65 *
dan_ackme 17:7268f365676b 66 * \note Currently only one remote client address is supported
dan_ackme 17:7268f365676b 67 *
dan_ackme 17:7268f365676b 68 \param remote The remote endpoint
dan_ackme 17:7268f365676b 69 \param packet The packet to be sent
dan_ackme 17:7268f365676b 70 \param length The length of the packet to be sent
dan_ackme 17:7268f365676b 71 \return the number of written bytes on success (>=0) or -1 on failure
dan_ackme 17:7268f365676b 72 */
dan_ackme 17:7268f365676b 73 int sendTo(Endpoint &remote, char *packet, int length);
dan_ackme 17:7268f365676b 74
dan_ackme 17:7268f365676b 75 /** Receive a packet from a remote endpoint
dan_ackme 17:7268f365676b 76 *
dan_ackme 17:7268f365676b 77 * \note Currently only one remote client address is supported
dan_ackme 17:7268f365676b 78 *
dan_ackme 17:7268f365676b 79 *
dan_ackme 17:7268f365676b 80 \param remote The remote endpoint
dan_ackme 17:7268f365676b 81 \param buffer The buffer for storing the incoming packet data. If a packet
dan_ackme 17:7268f365676b 82 is too long to fit in the supplied buffer, excess bytes are discarded
dan_ackme 17:7268f365676b 83 \param length The length of the buffer
dan_ackme 17:7268f365676b 84 \return the number of received bytes on success (>=0) or -1 on failure
dan_ackme 17:7268f365676b 85 */
dan_ackme 17:7268f365676b 86 int receiveFrom(Endpoint &remote, char *buffer, int length);
dan_ackme 17:7268f365676b 87
dan_ackme 17:7268f365676b 88
dan_ackme 17:7268f365676b 89 private:
dan_ackme 17:7268f365676b 90 int localPort;
dan_ackme 17:7268f365676b 91 };
dan_ackme 17:7268f365676b 92
dan_ackme 17:7268f365676b 93 #endif