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