clockUtils  1.1
clockUtils::sockets::UdpSocket Class Reference

class for sockets using udp More...

#include <UdpSocket.h>

Public Types

typedef std::function< void(std::vector< uint8_t > packet, std::string ip, uint16_t port, ClockError err)> packetCallback
 this function type is used receiving a packet using receiveCallback and is called for every packet More...
 

Public Member Functions

 UdpSocket ()
 constructor More...
 
 ~UdpSocket ()
 destructor, closes socket if not happened before More...
 
ClockError bind (uint16_t port)
 binds this socket to the given port for message receiving More...
 
void close ()
 closes a connection if socket is connected More...
 
ClockError writePacket (IPv4 ip, uint16_t port, const void *str, const size_t length)
 sends a packet being able to be completely received in one call of receivePacket More...
 
ClockError writePacket (IPv4 ip, uint16_t port, const std::vector< uint8_t > &vec)
 sends a packet being able to be completely received in one call of receivePacket More...
 
ClockError writePacket (IPv4 ip, uint16_t port, const std::string &str)
 sends a packet being able to be completely received in one call of receivePacket More...
 
ClockError writePacketAsync (IPv4 ip, uint16_t port, const void *str, const size_t length)
 sends a packet asynchronous being able to be completely received in one call of receivePacket More...
 
ClockError writePacketAsync (IPv4 ip, uint16_t port, const std::vector< uint8_t > &vec)
 sends a packet asynchronous being able to be completely received in one call of receivePacket More...
 
ClockError writePacketAsync (IPv4 ip, uint16_t port, const std::string &str)
 sends a packet asynchronous being able to be completely received in one call of receivePacket More...
 
ClockError write (IPv4 ip, uint16_t port, const void *str, size_t length)
 sends a packet, doesn't work with receivePacket More...
 
ClockError write (IPv4 ip, uint16_t port, const std::vector< uint8_t > &vec)
 sends a packet, doesn't work with receivePacket More...
 
ClockError write (IPv4 ip, uint16_t port, const std::string &str)
 sends a packet, doesn't work with receivePacket More...
 
ClockError writeAsync (IPv4 ip, uint16_t port, const void *str, size_t length)
 sends a message asynchronous, doesn't work with receivePacket More...
 
ClockError writeAsync (IPv4 ip, uint16_t port, const std::vector< uint8_t > &vec)
 sends a message asynchronous, doesn't work with receivePacket More...
 
ClockError writeAsync (IPv4 ip, uint16_t port, const std::string &str)
 sends a message asynchronous, doesn't work with receivePacket More...
 
template<typename... T>
ClockError writePacketToIP (const std::string &ip, uint16_t port, T... data)
 sends a packet being able to be completely received in one call of receivePacket More...
 
template<typename... T>
ClockError writePacketToIPAsync (const std::string &ip, uint16_t port, T... data)
 sends a packet asynchronous being able to be completely received in one call of receivePacket More...
 
template<typename... T>
ClockError writeToIP (const std::string &ip, uint16_t port, T... data)
 sends a packet, doesn't work with receivePacket More...
 
template<typename... T>
ClockError writeToIPAsync (const std::string &ip, uint16_t port, T... data)
 sends a message asynchronous, doesn't work with receivePacket More...
 
template<typename... T>
ClockError writePacketToHostname (const std::string &hostname, uint16_t port, T... data)
 sends a packet being able to be completely received in one call of receivePacket More...
 
template<typename... T>
ClockError writePacketToHostnameAsync (const std::string &hostname, uint16_t port, T... data)
 sends a packet asynchronous being able to be completely received in one call of receivePacket More...
 
template<typename... T>
ClockError writeToHostname (const std::string &hostname, uint16_t port, T... data)
 sends a packet, doesn't work with receivePacket More...
 
template<typename... T>
ClockError writeToHostnameAsync (const std::string &hostname, uint16_t port, T... data)
 sends a message asynchronous, doesn't work with receivePacket More...
 
ClockError receivePacket (std::vector< uint8_t > &buffer, std::string &ip, uint16_t &port)
 receives a packet sent with writePacket, doesn't work with write this functions blocks until a packet is received More...
 
ClockError receivePacket (std::string &buffer, std::string &ip, uint16_t &port)
 receives a packet sent with writePacket, doesn't work with write More...
 
ClockError receiveCallback (packetCallback pcb)
 calls the callback for every packet that is received on this socket This function will return immediately More...
 
template<class Container >
ClockError read (Container &buffer, std::string &ip, uint16_t &port)
 receives data on the socket More...
 

Public Attributes

const size_t MAX_PACKET_SIZE
 maximum size one packet is allowed to have, otherwise it can't be sent More...
 

Detailed Description

class for sockets using udp

Definition at line 74 of file UdpSocket.h.

Member Typedef Documentation

§ packetCallback

typedef std::function<void(std::vector<uint8_t> packet, std::string ip, uint16_t port, ClockError err)> clockUtils::sockets::UdpSocket::packetCallback

this function type is used receiving a packet using receiveCallback and is called for every packet

Definition at line 79 of file UdpSocket.h.

Constructor & Destructor Documentation

§ UdpSocket()

clockUtils::sockets::UdpSocket::UdpSocket ( )

constructor

§ ~UdpSocket()

clockUtils::sockets::UdpSocket::~UdpSocket ( )

destructor, closes socket if not happened before

Member Function Documentation

§ bind()

ClockError clockUtils::sockets::UdpSocket::bind ( uint16_t  port)

binds this socket to the given port for message receiving

§ close()

void clockUtils::sockets::UdpSocket::close ( )

closes a connection if socket is connected

§ read()

template<class Container >
ClockError clockUtils::sockets::UdpSocket::read ( Container &  buffer,
std::string &  ip,
uint16_t &  port 
)
inline

receives data on the socket

Definition at line 286 of file UdpSocket.h.

§ receiveCallback()

ClockError clockUtils::sockets::UdpSocket::receiveCallback ( packetCallback  pcb)

calls the callback for every packet that is received on this socket This function will return immediately

§ receivePacket() [1/2]

ClockError clockUtils::sockets::UdpSocket::receivePacket ( std::vector< uint8_t > &  buffer,
std::string &  ip,
uint16_t &  port 
)

receives a packet sent with writePacket, doesn't work with write this functions blocks until a packet is received

Parameters
[out]bufferThe data is stored in this buffer. Old data in this vector is deleted. Enough memory is allocated automatically.
[out]ipThe IP of the sender
[out]portThe port of the sender

§ receivePacket() [2/2]

ClockError clockUtils::sockets::UdpSocket::receivePacket ( std::string &  buffer,
std::string &  ip,
uint16_t &  port 
)

receives a packet sent with writePacket, doesn't work with write

Parameters
[out]bufferThe data is stored in this buffer. Old data in this string is deleted. Enough memory is allocated automatically.
[out]ipThe IP of the sender
[out]portThe port of the sender

§ write() [1/3]

ClockError clockUtils::sockets::UdpSocket::write ( IPv4  ip,
uint16_t  port,
const void *  str,
size_t  length 
)

sends a packet, doesn't work with receivePacket

Returns
if packet was sent, the method returns ClockError::SUCCESS, otherwise one of the other error codes. Can also return SUCCESS, if the socket was closed by peer and it wasn't detected yet

§ write() [2/3]

ClockError clockUtils::sockets::UdpSocket::write ( IPv4  ip,
uint16_t  port,
const std::vector< uint8_t > &  vec 
)
inline

sends a packet, doesn't work with receivePacket

Returns
if packet was sent, the method returns ClockError::SUCCESS, otherwise one of the other error codes. Can also return SUCCESS, if the socket was closed by peer and it wasn't detected yet

Definition at line 156 of file UdpSocket.h.

§ write() [3/3]

ClockError clockUtils::sockets::UdpSocket::write ( IPv4  ip,
uint16_t  port,
const std::string &  str 
)
inline

sends a packet, doesn't work with receivePacket

Returns
if packet was sent, the method returns ClockError::SUCCESS, otherwise one of the other error codes. Can also return SUCCESS, if the socket was closed by peer and it wasn't detected yet

Definition at line 164 of file UdpSocket.h.

§ writeAsync() [1/3]

ClockError clockUtils::sockets::UdpSocket::writeAsync ( IPv4  ip,
uint16_t  port,
const void *  str,
size_t  length 
)

sends a message asynchronous, doesn't work with receivePacket

Returns
if packet was sent, the method returns ClockError::SUCCESS, otherwise one of the other error codes. Can also return SUCCESS, if the socket was closed by peer and it wasn't detected yet

§ writeAsync() [2/3]

ClockError clockUtils::sockets::UdpSocket::writeAsync ( IPv4  ip,
uint16_t  port,
const std::vector< uint8_t > &  vec 
)

sends a message asynchronous, doesn't work with receivePacket

Returns
if packet was sent, the method returns ClockError::SUCCESS, otherwise one of the other error codes. Can also return SUCCESS, if the socket was closed by peer and it wasn't detected yet

§ writeAsync() [3/3]

ClockError clockUtils::sockets::UdpSocket::writeAsync ( IPv4  ip,
uint16_t  port,
const std::string &  str 
)
inline

sends a message asynchronous, doesn't work with receivePacket

Returns
if packet was sent, the method returns ClockError::SUCCESS, otherwise one of the other error codes. Can also return SUCCESS, if the socket was closed by peer and it wasn't detected yet

Definition at line 184 of file UdpSocket.h.

§ writePacket() [1/3]

ClockError clockUtils::sockets::UdpSocket::writePacket ( IPv4  ip,
uint16_t  port,
const void *  str,
const size_t  length 
)

sends a packet being able to be completely received in one call of receivePacket

Returns
if packet was sent, the method returns ClockError::SUCCESS, otherwise one of the other error codes. Can also return SUCCESS, if the socket was closed by peer and it wasn't detected yet

§ writePacket() [2/3]

ClockError clockUtils::sockets::UdpSocket::writePacket ( IPv4  ip,
uint16_t  port,
const std::vector< uint8_t > &  vec 
)

sends a packet being able to be completely received in one call of receivePacket

Returns
if packet was sent, the method returns ClockError::SUCCESS, otherwise one of the other error codes. Can also return SUCCESS, if the socket was closed by peer and it wasn't detected yet

§ writePacket() [3/3]

ClockError clockUtils::sockets::UdpSocket::writePacket ( IPv4  ip,
uint16_t  port,
const std::string &  str 
)
inline

sends a packet being able to be completely received in one call of receivePacket

Returns
if packet was sent, the method returns ClockError::SUCCESS, otherwise one of the other error codes. Can also return SUCCESS, if the socket was closed by peer and it wasn't detected yet

Definition at line 122 of file UdpSocket.h.

§ writePacketAsync() [1/3]

ClockError clockUtils::sockets::UdpSocket::writePacketAsync ( IPv4  ip,
uint16_t  port,
const void *  str,
const size_t  length 
)

sends a packet asynchronous being able to be completely received in one call of receivePacket

Returns
if packet was sent, the method returns ClockError::SUCCESS, otherwise one of the other error codes. Can also return SUCCESS, if the socket was closed by peer and it wasn't detected yet

§ writePacketAsync() [2/3]

ClockError clockUtils::sockets::UdpSocket::writePacketAsync ( IPv4  ip,
uint16_t  port,
const std::vector< uint8_t > &  vec 
)

sends a packet asynchronous being able to be completely received in one call of receivePacket

Returns
if packet was sent, the method returns ClockError::SUCCESS, otherwise one of the other error codes. Can also return SUCCESS, if the socket was closed by peer and it wasn't detected yet

§ writePacketAsync() [3/3]

ClockError clockUtils::sockets::UdpSocket::writePacketAsync ( IPv4  ip,
uint16_t  port,
const std::string &  str 
)
inline

sends a packet asynchronous being able to be completely received in one call of receivePacket

Returns
if packet was sent, the method returns ClockError::SUCCESS, otherwise one of the other error codes. Can also return SUCCESS, if the socket was closed by peer and it wasn't detected yet

Definition at line 142 of file UdpSocket.h.

§ writePacketToHostname()

template<typename... T>
ClockError clockUtils::sockets::UdpSocket::writePacketToHostname ( const std::string &  hostname,
uint16_t  port,
T...  data 
)
inline

sends a packet being able to be completely received in one call of receivePacket

Returns
if packet was sent, the method returns ClockError::SUCCESS, otherwise one of the other error codes. Can also return SUCCESS, if the socket was closed by peer and it wasn't detected yet

Definition at line 228 of file UdpSocket.h.

Here is the call graph for this function:

§ writePacketToHostnameAsync()

template<typename... T>
ClockError clockUtils::sockets::UdpSocket::writePacketToHostnameAsync ( const std::string &  hostname,
uint16_t  port,
T...  data 
)
inline

sends a packet asynchronous being able to be completely received in one call of receivePacket

Returns
if packet was sent, the method returns ClockError::SUCCESS, otherwise one of the other error codes. Can also return SUCCESS, if the socket was closed by peer and it wasn't detected yet

Definition at line 237 of file UdpSocket.h.

Here is the call graph for this function:

§ writePacketToIP()

template<typename... T>
ClockError clockUtils::sockets::UdpSocket::writePacketToIP ( const std::string &  ip,
uint16_t  port,
T...  data 
)
inline

sends a packet being able to be completely received in one call of receivePacket

Returns
if packet was sent, the method returns ClockError::SUCCESS, otherwise one of the other error codes. Can also return SUCCESS, if the socket was closed by peer and it wasn't detected yet

Definition at line 192 of file UdpSocket.h.

Here is the call graph for this function:

§ writePacketToIPAsync()

template<typename... T>
ClockError clockUtils::sockets::UdpSocket::writePacketToIPAsync ( const std::string &  ip,
uint16_t  port,
T...  data 
)
inline

sends a packet asynchronous being able to be completely received in one call of receivePacket

Returns
if packet was sent, the method returns ClockError::SUCCESS, otherwise one of the other error codes. Can also return SUCCESS, if the socket was closed by peer and it wasn't detected yet

Definition at line 201 of file UdpSocket.h.

Here is the call graph for this function:

§ writeToHostname()

template<typename... T>
ClockError clockUtils::sockets::UdpSocket::writeToHostname ( const std::string &  hostname,
uint16_t  port,
T...  data 
)
inline

sends a packet, doesn't work with receivePacket

Returns
if packet was sent, the method returns ClockError::SUCCESS, otherwise one of the other error codes. Can also return SUCCESS, if the socket was closed by peer and it wasn't detected yet

Definition at line 246 of file UdpSocket.h.

Here is the call graph for this function:

§ writeToHostnameAsync()

template<typename... T>
ClockError clockUtils::sockets::UdpSocket::writeToHostnameAsync ( const std::string &  hostname,
uint16_t  port,
T...  data 
)
inline

sends a message asynchronous, doesn't work with receivePacket

Returns
if packet was sent, the method returns ClockError::SUCCESS, otherwise one of the other error codes. Can also return SUCCESS, if the socket was closed by peer and it wasn't detected yet

Definition at line 255 of file UdpSocket.h.

Here is the call graph for this function:

§ writeToIP()

template<typename... T>
ClockError clockUtils::sockets::UdpSocket::writeToIP ( const std::string &  ip,
uint16_t  port,
T...  data 
)
inline

sends a packet, doesn't work with receivePacket

Returns
if packet was sent, the method returns ClockError::SUCCESS, otherwise one of the other error codes. Can also return SUCCESS, if the socket was closed by peer and it wasn't detected yet

Definition at line 210 of file UdpSocket.h.

Here is the call graph for this function:

§ writeToIPAsync()

template<typename... T>
ClockError clockUtils::sockets::UdpSocket::writeToIPAsync ( const std::string &  ip,
uint16_t  port,
T...  data 
)
inline

sends a message asynchronous, doesn't work with receivePacket

Returns
if packet was sent, the method returns ClockError::SUCCESS, otherwise one of the other error codes. Can also return SUCCESS, if the socket was closed by peer and it wasn't detected yet

Definition at line 219 of file UdpSocket.h.

Here is the call graph for this function:

Member Data Documentation

§ MAX_PACKET_SIZE

const size_t clockUtils::sockets::UdpSocket::MAX_PACKET_SIZE

maximum size one packet is allowed to have, otherwise it can't be sent

Definition at line 84 of file UdpSocket.h.


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