-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUDP_socket.h
37 lines (29 loc) · 878 Bytes
/
UDP_socket.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//
// Created by Eugenio Moro on 25/10/22.
//
#ifndef PROTOBUF_CPP_EXAMPLES_UDP_SOCKET_H
#define PROTOBUF_CPP_EXAMPLES_UDP_SOCKET_H
#include <boost/asio.hpp>
#include <boost/array.hpp>
#include <boost/bind.hpp>
#include <thread>
#include <iostream>
#define LOOPBACK "127.0.0.1"
#define MAXLEN 1024
namespace basio = boost::asio;
class UDP_socket {
basio::io_context io_context;
basio::ip::udp::endpoint ep;
basio::ip::udp::socket* in_socket;
basio::ip::udp::socket out_socket{io_context};
basio::ip::udp::endpoint* in_ep;
basio::ip::udp::endpoint* out_ep;
public:
uint16_t in_port;
uint16_t out_port;
UDP_socket(uint16_t in_port, uint16_t out_port);
std::size_t send(char* buf, std::size_t len);
std::size_t sendAsString(std::string buffer);
std::size_t receive(char** buf);
};
#endif //PROTOBUF_CPP_EXAMPLES_UDP_SOCKET_H