The Micro C++ Library
|
A DatagramSocket represents a User Datagram Protocol (UDP) Socket for sending and receiving single (short) datagram packets. More...
#include <micxx.hxx>
Inherits micxx::Socket.
Inherited by micxx::MulticastSocket.
Public Member Functions | |
DatagramSocket () | |
Create a new DatagramSocket. | |
virtual void | bind (unsigned short port=0) |
Bind the Socket to INADDR_ANY and the specified port. | |
virtual bool | getRecvDstAddr () const |
The current value for socket option IP_PKTINFO (resp. IP_RECVDSTADDR for some systems like e.g. Solaris) of level IPPROTO_IP . | |
virtual long | recv (Datagram &datagram) |
Try to receive a single datagram packet from the bound DatagramSocket. | |
virtual long | sendto (const void *buffer, std::size_t size, const SocketAddress &socketAddress) |
Try to send a single datagram packet of the specified size to SocketAddress socketAddress. | |
virtual void | setRecvDstAddr (bool value) |
Set the current value for socket option IP_PKTINFO (resp. IP_RECVDSTADDR for some systems like e.g. Solaris) of level IPPROTO_IP . | |
Protected Member Functions | |
virtual void | createSocket (int addressFamily) |
Create the underlying socket descriptor for the specified addressFamily. |
A DatagramSocket represents a User Datagram Protocol (UDP) Socket for sending and receiving single (short) datagram packets.
UDP does not guarantee reliability or ordering of packets.
Example:
micxx::DatagramSocket datagramSocket; micxx::InetAddress serverAddress(8000); datagramSocket.bind(serverAddress); micxx::Datagram datagram(MSG_SIZE); datagramSocket.recv(datagram); ...
micxx::DatagramSocket::DatagramSocket | ( | ) |
Create a new DatagramSocket.
Same as Socket(SOCK_DGRAM).
virtual void micxx::DatagramSocket::bind | ( | unsigned short | port = 0 | ) | [virtual] |
Bind the Socket to INADDR_ANY
and the specified port.
virtual void micxx::DatagramSocket::createSocket | ( | int | addressFamily | ) | [protected, virtual] |
Create the underlying socket descriptor for the specified addressFamily.
addressFamily | The family of the stored SocketAddress. |
Reimplemented from micxx::Socket.
Reimplemented in micxx::MulticastSocket.
virtual bool micxx::DatagramSocket::getRecvDstAddr | ( | ) | const [virtual] |
The current value for socket option IP_PKTINFO
(resp. IP_RECVDSTADDR
for some systems like e.g. Solaris) of level IPPROTO_IP
.
virtual long micxx::DatagramSocket::recv | ( | Datagram & | datagram | ) | [virtual] |
Try to receive a single datagram packet from the bound DatagramSocket.
datagram | The destination datagram where to store the received datagram packet. |
virtual long micxx::DatagramSocket::sendto | ( | const void * | buffer, |
std::size_t | size, | ||
const SocketAddress & | socketAddress | ||
) | [virtual] |
Try to send a single datagram packet of the specified size to SocketAddress socketAddress.
virtual void micxx::DatagramSocket::setRecvDstAddr | ( | bool | value | ) | [virtual] |
Set the current value for socket option IP_PKTINFO
(resp. IP_RECVDSTADDR
for some systems like e.g. Solaris) of level IPPROTO_IP
.