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