UDP (Sender/Listener) Class.
More...
#include <udp.hpp>
|
| | UdpSocket () |
| | Creates a socket and configures basic options.
|
| |
| | ~UdpSocket () |
| | Closes the socket.
|
| |
| void | setTimeout (int sec) |
| | Sets the send/receive timeout.
|
| |
| void | setBroadcast (bool enable) |
| | Enables or disables broadcast.
|
| |
| bool | bind (int port) |
| | Binds to a specified port and prepares for receiving data.
|
| |
| std::vector< uint8_t > | receive (size_t max_len=1024) |
| | Receives data.
|
| |
| bool | setDestination (const std::string &host, int port) |
| | Sets a fixed destination address (uses connect). This enables the use of the send() method.
|
| |
| ssize_t | send (const std::vector< uint8_t > &data) |
| | Sends data to the fixed destination.
|
| |
| ssize_t | sendTo (const std::vector< uint8_t > &data, const std::string &host, int port) |
| | Sends data to a specified destination (uses sendto). Can be used without calling setDestination().
|
| |
UDP (Sender/Listener) Class.
◆ UdpSocket()
| common::UdpSocket::UdpSocket |
( |
| ) |
|
Creates a socket and configures basic options.
◆ ~UdpSocket()
| common::UdpSocket::~UdpSocket |
( |
| ) |
|
◆ bind()
| bool common::UdpSocket::bind |
( |
int |
port | ) |
|
Binds to a specified port and prepares for receiving data.
- Parameters
-
| port | Port number to listen on. |
- Returns
- true on success, false on failure.
◆ receive()
| std::vector< uint8_t > common::UdpSocket::receive |
( |
size_t |
max_len = 1024 | ) |
|
Receives data.
- Parameters
-
| max_len | Maximum buffer size for reception. |
- Returns
- std::vector<uint8_t> Received data (returns an empty vector on timeout or error).
◆ send()
| ssize_t common::UdpSocket::send |
( |
const std::vector< uint8_t > & |
data | ) |
|
Sends data to the fixed destination.
- Parameters
-
- Returns
- ssize_t Number of bytes sent.
◆ sendTo()
| ssize_t common::UdpSocket::sendTo |
( |
const std::vector< uint8_t > & |
data, |
|
|
const std::string & |
host, |
|
|
int |
port |
|
) |
| |
Sends data to a specified destination (uses sendto). Can be used without calling setDestination().
- Parameters
-
| data | Data to be sent. |
| host | Destination IP address. |
| port | Destination port number. |
- Returns
- ssize_t Number of bytes sent.
◆ setBroadcast()
| void common::UdpSocket::setBroadcast |
( |
bool |
enable | ) |
|
Enables or disables broadcast.
- Parameters
-
| enable | Set to true to enable broadcast. |
◆ setDestination()
| bool common::UdpSocket::setDestination |
( |
const std::string & |
host, |
|
|
int |
port |
|
) |
| |
Sets a fixed destination address (uses connect). This enables the use of the send() method.
- Parameters
-
| host | Destination IP address. |
| port | Destination port number. |
- Returns
- true on success.
◆ setTimeout()
| void common::UdpSocket::setTimeout |
( |
int |
sec | ) |
|
Sets the send/receive timeout.
- Parameters
-
| sec | Timeout duration in seconds. |
The documentation for this class was generated from the following files:
- src/common/custom_socket/include/custom_socket/udp.hpp
- src/common/custom_socket/src/udp.cpp