Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of WIZnetInterface by
Socket/UDPSocket.h@0:6f28332c466f, 2015-06-15 (annotated)
- Committer:
- Soohwan Kim
- Date:
- Mon Jun 15 11:18:37 2015 +0900
- Revision:
- 0:6f28332c466f
initial version
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Soohwan Kim |
0:6f28332c466f | 1 | /* Copyright (C) 2012 mbed.org, MIT License |
| Soohwan Kim |
0:6f28332c466f | 2 | * |
| Soohwan Kim |
0:6f28332c466f | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
| Soohwan Kim |
0:6f28332c466f | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
| Soohwan Kim |
0:6f28332c466f | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
| Soohwan Kim |
0:6f28332c466f | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
| Soohwan Kim |
0:6f28332c466f | 7 | * furnished to do so, subject to the following conditions: |
| Soohwan Kim |
0:6f28332c466f | 8 | * |
| Soohwan Kim |
0:6f28332c466f | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
| Soohwan Kim |
0:6f28332c466f | 10 | * substantial portions of the Software. |
| Soohwan Kim |
0:6f28332c466f | 11 | * |
| Soohwan Kim |
0:6f28332c466f | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
| Soohwan Kim |
0:6f28332c466f | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| Soohwan Kim |
0:6f28332c466f | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| Soohwan Kim |
0:6f28332c466f | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| Soohwan Kim |
0:6f28332c466f | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| Soohwan Kim |
0:6f28332c466f | 17 | */ |
| Soohwan Kim |
0:6f28332c466f | 18 | |
| Soohwan Kim |
0:6f28332c466f | 19 | #ifndef UDPSOCKET_H |
| Soohwan Kim |
0:6f28332c466f | 20 | #define UDPSOCKET_H |
| Soohwan Kim |
0:6f28332c466f | 21 | |
| Soohwan Kim |
0:6f28332c466f | 22 | #include "Endpoint.h" |
| Soohwan Kim |
0:6f28332c466f | 23 | #include "Socket.h" |
| Soohwan Kim |
0:6f28332c466f | 24 | |
| Soohwan Kim |
0:6f28332c466f | 25 | /** |
| Soohwan Kim |
0:6f28332c466f | 26 | UDP Socket |
| Soohwan Kim |
0:6f28332c466f | 27 | */ |
| Soohwan Kim |
0:6f28332c466f | 28 | class UDPSocket: public Socket { |
| Soohwan Kim |
0:6f28332c466f | 29 | |
| Soohwan Kim |
0:6f28332c466f | 30 | public: |
| Soohwan Kim |
0:6f28332c466f | 31 | /** Instantiate an UDP Socket. |
| Soohwan Kim |
0:6f28332c466f | 32 | */ |
| Soohwan Kim |
0:6f28332c466f | 33 | UDPSocket(); |
| Soohwan Kim |
0:6f28332c466f | 34 | |
| Soohwan Kim |
0:6f28332c466f | 35 | /** Init the UDP Client Socket without binding it to any specific port |
| Soohwan Kim |
0:6f28332c466f | 36 | \return 0 on success, -1 on failure. |
| Soohwan Kim |
0:6f28332c466f | 37 | */ |
| Soohwan Kim |
0:6f28332c466f | 38 | int init(void); |
| Soohwan Kim |
0:6f28332c466f | 39 | |
| Soohwan Kim |
0:6f28332c466f | 40 | /** Bind a UDP Server Socket to a specific port |
| Soohwan Kim |
0:6f28332c466f | 41 | \param port The port to listen for incoming connections on |
| Soohwan Kim |
0:6f28332c466f | 42 | \return 0 on success, -1 on failure. |
| Soohwan Kim |
0:6f28332c466f | 43 | */ |
| Soohwan Kim |
0:6f28332c466f | 44 | int bind(int port = -1); |
| Soohwan Kim |
0:6f28332c466f | 45 | |
| Soohwan Kim |
0:6f28332c466f | 46 | /** Send a packet to a remote endpoint |
| Soohwan Kim |
0:6f28332c466f | 47 | \param remote The remote endpoint |
| Soohwan Kim |
0:6f28332c466f | 48 | \param packet The packet to be sent |
| Soohwan Kim |
0:6f28332c466f | 49 | \param length The length of the packet to be sent |
| Soohwan Kim |
0:6f28332c466f | 50 | \return the number of written bytes on success (>=0) or -1 on failure |
| Soohwan Kim |
0:6f28332c466f | 51 | */ |
| Soohwan Kim |
0:6f28332c466f | 52 | int sendTo(Endpoint &remote, char *packet, int length); |
| Soohwan Kim |
0:6f28332c466f | 53 | |
| Soohwan Kim |
0:6f28332c466f | 54 | /** Receive a packet from a remote endpoint |
| Soohwan Kim |
0:6f28332c466f | 55 | \param remote The remote endpoint |
| Soohwan Kim |
0:6f28332c466f | 56 | \param buffer The buffer for storing the incoming packet data. If a packet |
| Soohwan Kim |
0:6f28332c466f | 57 | is too long to fit in the supplied buffer, excess bytes are discarded |
| Soohwan Kim |
0:6f28332c466f | 58 | \param length The length of the buffer |
| Soohwan Kim |
0:6f28332c466f | 59 | \return the number of received bytes on success (>=0) or -1 on failure |
| Soohwan Kim |
0:6f28332c466f | 60 | */ |
| Soohwan Kim |
0:6f28332c466f | 61 | int receiveFrom(Endpoint &remote, char *buffer, int length); |
| Soohwan Kim |
0:6f28332c466f | 62 | |
| Soohwan Kim |
0:6f28332c466f | 63 | private: |
| Soohwan Kim |
0:6f28332c466f | 64 | void confEndpoint(Endpoint & ep); |
| Soohwan Kim |
0:6f28332c466f | 65 | void readEndpoint(Endpoint & ep, uint8_t info[]); |
| Soohwan Kim |
0:6f28332c466f | 66 | }; |
| Soohwan Kim |
0:6f28332c466f | 67 | |
| Soohwan Kim |
0:6f28332c466f | 68 | #endif |
| Soohwan Kim |
0:6f28332c466f | 69 |
