Mistake on this page?
Report an issue in GitHub or email us
Public Member Functions | Protected Member Functions | Protected Attributes
UDPSocket Class Reference

#include <UDPSocket.h>

Inheritance diagram for UDPSocket:
Socket EchoSocket

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)
 
template<typename S >
nsapi_error_t open (S *stack)
 
nsapi_error_t close ()
 
int join_multicast_group (const SocketAddress &address)
 
int leave_multicast_group (const SocketAddress &address)
 
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)
 
nsapi_error_t setsockopt (int level, int optname, const void *optval, unsigned optlen)
 
nsapi_error_t getsockopt (int level, int optname, void *optval, unsigned *optlen)
 
void sigio (mbed::Callback< void()> func)
 
void attach (mbed::Callback< void()> func)
 
template<typename T , typename M >
void attach (T *obj, M method)
 

Protected Member Functions

virtual nsapi_protocol_t get_proto ()
 
virtual void event ()
 
- Protected Member Functions inherited from Socket
int modify_multicast_group (const SocketAddress &address, nsapi_socket_option_t socketopt)
 

Protected Attributes

volatile unsigned _pending
 
rtos::EventFlags _event_flag
 
- Protected Attributes inherited from Socket
NetworkStack_stack
 
nsapi_socket_t _socket
 
uint32_t _timeout
 
mbed::Callback< void()> _event
 
mbed::Callback< void()> _callback
 
rtos::Mutex _lock
 

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 datagram over a UDP socket

Receives a datagram and stores the source address in address if address is not NULL. Returns the number of bytes written into the buffer. If the datagram is larger than the buffer, the excess data is silently discarded.

By default, recvfrom blocks until a datagram is received. If socket is set to non-blocking or times out with no datagram, NSAPI_ERROR_WOULD_BLOCK is returned.

Parameters
addressDestination for the source address or NULL
dataDestination buffer for datagram 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:
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.