Babel  1
The voip software that only works on your local network
Loading...
Searching...
No Matches
UDP.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2024
3** send_receive
4** File description:
5** UDP.hpp
6*/
7
13#pragma once
14
15#include <string>
16#include <iostream>
17#include <asio.hpp>
18#include <queue>
19#include "Logging.hpp"
20
21namespace Network
22{
27 class UDP {
28 public:
37 UDP(asio::io_context &io_context, const std::string &ip, int port, bool is_sender);
41 ~UDP();
42
50 void sendTo(const std::string &message, const std::string &address, int port);
51
60 void sendRaw(const char *data, std::size_t size, const std::string &address, int port);
61
69 std::string receiveFrom(std::string &address, int &port);
70
76 bool isConnectionAlive();
77
83 std::string fetchPacket();
84
85 private:
86 bool _is_sender;
87 asio::ip::udp::socket _socket;
88 std::queue<std::string> _received_packets;
89 };
90}
Aggregates logging-related headers.
A class for handling UDP network communication.
Definition UDP.hpp:27
std::string fetchPacket()
Fetch a packet from the received packets queue.
Definition UDP.cpp:122
void sendRaw(const char *data, std::size_t size, const std::string &address, int port)
Send raw data to a specified address and port.
Definition UDP.cpp:68
UDP(asio::io_context &io_context, const std::string &ip, int port, bool is_sender)
Construct a new UDP object.
Definition UDP.cpp:26
~UDP()
Destroy the UDP object.
Definition UDP.cpp:42
void sendTo(const std::string &message, const std::string &address, int port)
Send a message to a specified address and port.
Definition UDP.cpp:54
bool isConnectionAlive()
Check if the connection is alive.
Definition UDP.cpp:112
std::string receiveFrom(std::string &address, int &port)
Receive a message from a specified address and port.
Definition UDP.cpp:81