Babel  1
The voip software that only works on your local network
Loading...
Searching...
No Matches
Network::UDP Class Reference

A class for handling UDP network communication. More...

#include <UDP.hpp>

Collaboration diagram for Network::UDP:
Collaboration graph

Public Member Functions

 UDP (asio::io_context &io_context, const std::string &ip, int port, bool is_sender)
 Construct a new UDP object.
 
 ~UDP ()
 Destroy the UDP object.
 
void sendTo (const std::string &message, const std::string &address, int port)
 Send a message to a specified address and port.
 
void sendRaw (const char *data, std::size_t size, const std::string &address, int port)
 Send raw data to a specified address and port.
 
std::string receiveFrom (std::string &address, int &port)
 Receive a message from a specified address and port.
 
bool isConnectionAlive ()
 Check if the connection is alive.
 
std::string fetchPacket ()
 Fetch a packet from the received packets queue.
 

Detailed Description

A class for handling UDP network communication.

Definition at line 27 of file UDP.hpp.

Constructor & Destructor Documentation

◆ UDP()

Network::UDP::UDP ( asio::io_context & io_context,
const std::string & ip,
int port,
bool is_sender )

Construct a new UDP object.

Constructs a new UDP object.

Parameters
io_contextThe ASIO I/O context.
ipThe IP address to bind or connect to.
portThe port number to bind or connect to.
is_senderIndicates whether the instance is for sending or receiving.
io_contextThe ASIO I/O context.
ipThe IP address to bind or connect to.
portThe port number to bind or connect to.
is_senderTrue if the UDP object is for sending, false if for receiving.

Definition at line 26 of file UDP.cpp.

◆ ~UDP()

Network::UDP::~UDP ( )

Destroy the UDP object.

Destroys the UDP object.

Definition at line 42 of file UDP.cpp.

Member Function Documentation

◆ fetchPacket()

std::string Network::UDP::fetchPacket ( )

Fetch a packet from the received packets queue.

Fetches a received packet from the queue.

Returns
The fetched packet.
The received packet.

Definition at line 122 of file UDP.cpp.

◆ isConnectionAlive()

bool Network::UDP::isConnectionAlive ( )

Check if the connection is alive.

Checks if the connection is alive.

Returns
true if the connection is alive; false otherwise.
True if the connection is alive, otherwise false.

Definition at line 112 of file UDP.cpp.

◆ receiveFrom()

std::string Network::UDP::receiveFrom ( std::string & address,
int & port )

Receive a message from a specified address and port.

Receives a message from a remote endpoint.

Parameters
addressThe source IP address.
portThe source port number.
Returns
The received message.

Definition at line 81 of file UDP.cpp.

◆ sendRaw()

void Network::UDP::sendRaw ( const char * data,
std::size_t size,
const std::string & address,
int port )

Send raw data to a specified address and port.

Sends raw data to the specified address and port.

Parameters
dataThe raw data to send.
sizeThe size of the data.
addressThe destination IP address.
portThe destination port number.

Definition at line 68 of file UDP.cpp.

◆ sendTo()

void Network::UDP::sendTo ( const std::string & message,
const std::string & address,
int port )

Send a message to a specified address and port.

Sends a message to the specified address and port.

Parameters
messageThe message to send.
addressThe destination IP address.
portThe destination port number.

Definition at line 54 of file UDP.cpp.


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