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 MTS-Socket by
UDPSocket.h@20:a74e92329ba6, 2014-12-30 (annotated)
- Committer:
- Mike Fiore 
- Date:
- Tue Dec 30 08:11:16 2014 -0600
- Revision:
- 20:a74e92329ba6
- Parent:
- 9:b2e3862705fc
remove stdint inclusion from UDPSocket.h
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| mfiore | 0:eef30dbe1130 | 1 | #ifndef UDPSOCKET_H | 
| mfiore | 0:eef30dbe1130 | 2 | #define UDPSOCKET_H | 
| mfiore | 0:eef30dbe1130 | 3 | |
| mfiore | 9:b2e3862705fc | 4 | #include "Endpoint.h" | 
| mfiore | 9:b2e3862705fc | 5 | #include "Socket.h" | 
| mfiore | 9:b2e3862705fc | 6 | |
| mfiore | 9:b2e3862705fc | 7 | /** | 
| mfiore | 9:b2e3862705fc | 8 | UDP Socket | 
| mfiore | 9:b2e3862705fc | 9 | */ | 
| mfiore | 9:b2e3862705fc | 10 | class UDPSocket: public Socket | 
| mfiore | 9:b2e3862705fc | 11 | { | 
| mfiore | 9:b2e3862705fc | 12 | |
| mfiore | 9:b2e3862705fc | 13 | public: | 
| mfiore | 9:b2e3862705fc | 14 | /** Instantiate an UDP Socket. | 
| mfiore | 9:b2e3862705fc | 15 | */ | 
| mfiore | 9:b2e3862705fc | 16 | UDPSocket(); | 
| mfiore | 9:b2e3862705fc | 17 | |
| mfiore | 9:b2e3862705fc | 18 | /** Init the UDP Client Socket without binding it to any specific port | 
| mfiore | 9:b2e3862705fc | 19 | \return 0 on success, -1 on failure. | 
| mfiore | 9:b2e3862705fc | 20 | */ | 
| mfiore | 9:b2e3862705fc | 21 | int init(void); | 
| mfiore | 9:b2e3862705fc | 22 | |
| mfiore | 9:b2e3862705fc | 23 | /** Bind a UDP Server Socket to a specific port | 
| mfiore | 9:b2e3862705fc | 24 | \param port The port to listen for incoming connections on | 
| mfiore | 9:b2e3862705fc | 25 | \return 0 on success, -1 on failure. | 
| mfiore | 9:b2e3862705fc | 26 | */ | 
| mfiore | 9:b2e3862705fc | 27 | int bind(int port = -1); | 
| mfiore | 9:b2e3862705fc | 28 | |
| mfiore | 9:b2e3862705fc | 29 | /** Send a packet to a remote endpoint | 
| mfiore | 9:b2e3862705fc | 30 | \param remote The remote endpoint | 
| mfiore | 9:b2e3862705fc | 31 | \param packet The packet to be sent | 
| mfiore | 9:b2e3862705fc | 32 | \param length The length of the packet to be sent | 
| mfiore | 9:b2e3862705fc | 33 | \return the number of written bytes on success (>=0) or -1 on failure | 
| mfiore | 9:b2e3862705fc | 34 | */ | 
| mfiore | 9:b2e3862705fc | 35 | int sendTo(Endpoint &remote, char *packet, int length); | 
| mfiore | 9:b2e3862705fc | 36 | |
| mfiore | 9:b2e3862705fc | 37 | /** Receive a packet from a remote endpoint | 
| mfiore | 9:b2e3862705fc | 38 | \param remote The remote endpoint | 
| mfiore | 9:b2e3862705fc | 39 | \param buffer The buffer for storing the incoming packet data. If a packet | 
| mfiore | 9:b2e3862705fc | 40 | is too long to fit in the supplied buffer, excess bytes are discarded | 
| mfiore | 9:b2e3862705fc | 41 | \param length The length of the buffer | 
| mfiore | 9:b2e3862705fc | 42 | \return the number of received bytes on success (>=0) or -1 on failure | 
| mfiore | 9:b2e3862705fc | 43 | */ | 
| mfiore | 9:b2e3862705fc | 44 | int receiveFrom(Endpoint &remote, char *buffer, int length); | 
| mfiore | 9:b2e3862705fc | 45 | }; | 
| mfiore | 9:b2e3862705fc | 46 | |
| Mike Fiore | 1:096f484f3ae6 | 47 | #endif | 
