Public Member Functions
UDPSocket Class Reference

#include <UDPSocket.h>

Inheritance diagram for UDPSocket:
Socket

Public Member Functions

 UDPSocket ()
 
template<typename S >
 UDPSocket (S *stack)
 
virtual ~UDPSocket ()
 
nsapi_size_or_error_t sendto (const char *host, uint16_t port, const void *data, nsapi_size_t size)
 
nsapi_size_or_error_t sendto (const SocketAddress &address, const void *data, nsapi_size_t size)
 
nsapi_size_or_error_t recvfrom (SocketAddress *address, void *data, nsapi_size_t size)
 
- Public Member Functions inherited from Socket
virtual ~Socket ()
 
nsapi_error_t open (NetworkStack *stack)
 
nsapi_error_t close ()
 
nsapi_error_t bind (uint16_t port)
 
nsapi_error_t bind (const char *address, uint16_t port)
 
nsapi_error_t bind (const SocketAddress &address)
 
void set_blocking (bool blocking)
 
void set_timeout (int timeout)
 
void sigio (mbed::Callback< void()> func)
 
void attach (mbed::Callback< void()> func)
 
template<typename T , typename M >
void attach (T *obj, M method)
 

Detailed Description

UDP socket

Constructor & Destructor Documentation

UDPSocket::UDPSocket ( )

Create an uninitialized socket

Must call open to initialize the socket on a network stack.

template<typename S >
UDPSocket::UDPSocket ( S *  stack)
inline

Create a socket on a network interface

Creates and opens a socket on the network stack of the given network interface.

Parameters
stackNetwork stack as target for socket
UDPSocket::~UDPSocket ( )
virtual

Destroy a socket

Closes socket if the socket is still open

Member Function Documentation

nsapi_size_or_error_t UDPSocket::recvfrom ( SocketAddress *  address,
void *  data,
nsapi_size_t  size 
)

Receive a packet over a UDP socket

Receives data and stores the source address in address if address is not NULL. Returns the number of bytes received into the buffer.

By default, recvfrom blocks until data is sent. If socket is set to non-blocking or times out, NSAPI_ERROR_WOULD_BLOCK is returned immediately.

Parameters
addressDestination for the source address or NULL
dataDestination buffer for data received from the host
sizeSize of the buffer in bytes
Returns
Number of received bytes on success, negative error code on failure
nsapi_size_or_error_t UDPSocket::sendto ( const char *  host,
uint16_t  port,
const void *  data,
nsapi_size_t  size 
)

Send a packet over a UDP socket

Sends data to the specified address specified by either a domain name or an IP address and port. Returns the number of bytes sent from the buffer.

By default, sendto blocks until data is sent. If socket is set to non-blocking or times out, NSAPI_ERROR_WOULD_BLOCK is returned immediately.

Parameters
hostHostname of the remote host
portPort of the remote host
dataBuffer of data to send to the host
sizeSize of the buffer in bytes
Returns
Number of sent bytes on success, negative error code on failure
nsapi_size_or_error_t UDPSocket::sendto ( const SocketAddress &  address,
const void *  data,
nsapi_size_t  size 
)

Send a packet over a UDP socket

Sends data to the specified address. Returns the number of bytes sent from the buffer.

By default, sendto blocks until data is sent. If socket is set to non-blocking or times out, NSAPI_ERROR_WOULD_BLOCK is returned immediately.

Parameters
addressThe SocketAddress of the remote host
dataBuffer of data to send to the host
sizeSize of the buffer in bytes
Returns
Number of sent bytes on success, negative error code on failure

The documentation for this class was generated from the following files: