Babel  1
The voip software that only works on your local network
Loading...
Searching...
No Matches
TCP.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2024
3** send_receive
4** File description:
5** TCP.hpp
6*/
7
13#pragma once
14
15#include <string>
16#include <iostream>
17#include <asio.hpp>
18#include <queue>
19#include <thread>
20#include <memory>
21#include "Logging.hpp"
22
23namespace Network
24{
29 class TCP {
30 public:
39 TCP(asio::io_context &io_context, const std::string &ip, int port, bool is_sender);
43 ~TCP();
44
50 void sendTo(const std::string &message);
51
57 std::string receive();
58
64 bool isConnectionAlive();
65
71 std::string fetchPacket();
72
73 private:
77 void startAccept();
78
82 void startRead();
83
84 asio::io_context &_io_context;
85 asio::ip::tcp::socket _socket;
86 asio::ip::tcp::acceptor _acceptor;
87 bool _is_sender;
88 std::queue<std::string> _received_packets;
89 std::shared_ptr<std::thread> _server_thread;
90 };
91}
Aggregates logging-related headers.
A class for handling TCP network communication.
Definition TCP.hpp:29
~TCP()
Destroy the TCP object.
Definition TCP.cpp:43
TCP(asio::io_context &io_context, const std::string &ip, int port, bool is_sender)
Construct a new TCP object.
Definition TCP.cpp:19
std::string fetchPacket()
Fetch a packet from the received packets queue.
Definition TCP.cpp:127
bool isConnectionAlive()
Check if the connection is alive.
Definition TCP.cpp:117
void sendTo(const std::string &message)
Send a message to the connected peer.
Definition TCP.cpp:57
std::string receive()
Receive a message from the connected peer.
Definition TCP.cpp:102