wip
Dependents: EthernetInterface_vz
Fork of Socket by
Diff: UDPSocket.h
- Revision:
- 5:300e7ad2dc1d
- Parent:
- 3:e6474399e057
- Child:
- 6:cd2e5559786d
--- a/UDPSocket.h Thu Jul 26 10:07:43 2012 +0000 +++ b/UDPSocket.h Thu Jul 26 15:07:32 2012 +0000 @@ -20,45 +20,45 @@ #define UDPSOCKET_H #include "Socket/Socket.h" +#include "Socket/UDPPacket.h" #include <cstdint> /** This is a C++ abstraction for UDP networking sockets. */ class UDPSocket : public Socket { - public: + +public: /** Instantiate a UDP Socket. */ UDPSocket(); ~UDPSocket(); + int init(void); + /** Bind a UDP Server Socket to a specific port For a listening socket, bind the socket to the following port. \param port The port to listen for incoming connections on, using 0 here will select a random port. \return 0 on success, -1 on failure. */ int bind(int port); - - /** Send data to a remote host. - \param data The buffer to send to the host. - \param length The length of the buffer to send. - \param host The host to send data to. It can either be an IP Address or a hostname that will be resolved with DNS. - \param port The host's port to send data to. + + /** Send a packet to the remote host. + \param packet UDP Packet to be sent to the remote host \param timeout The maximum amount of time in ms to wait while trying to send the buffer. \return the number of written bytes on success (>=0) or -1 on failure */ - int sendTo(char* data, int length, char* host, int port, int timeout = 0); - + int sendTo(UDPPacket& packet, int timeout=0); + /** Receive data from a remote host. - \param data The buffer in which to store the data received from the host. - \param length The maximum length of the buffer. - \param host The reference that will point to the client's IP address. - \param port The reference that will point to the client's port. + If a message is too long to fit in the supplied packet, excess bytes are + discarded. + \param packet UDP Packet received from the remote host \param timeout The maximum amount of time in ms to wait while trying to receive data. \return the number of received bytes on success (>=0) or -1 on failure */ - int receiveFrom(char* data, int length, char** host, int* port, int timeout = 0); + int receiveFrom(UDPPacket& packet, int timeout=0); }; #endif