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