Botball Game State
A game stared library for Botball, it helps model the table and different phases of the competition.
Loading...
Searching...
No Matches
Socket.h
1#pragma once
2#include <memory>
3#include <netinet/in.h>
4#include <spdlog/spdlog.h>
5#include "Util.h"
6using namespace Util;
7
8class Socket {
9protected:
10 int m_fd = -1;
11 bool m_closed = true;
12 std::shared_ptr<spdlog::logger> m_log;
13
14private:
15 sockaddr_in addr = {};
16
17public:
18 virtual ~Socket() = default;
19
23 void init_socket(uint16_t port);
24
29 void init_server(uint16_t port);
30
36 void init_client(const std::string &ip_address, uint16_t port);
37
43 void recv_all(void *buf, size_t len);
44
50 void send_all(const void *buf, size_t len) const;
51
58 void send_json(const json &data) const;
59
66 [[nodiscard]] std::optional<json> recv_json();
67
72
77};
Definition Socket.h:8
void recv_all(void *buf, size_t len)
void send_json(const json &data) const
void send_all(const void *buf, size_t len) const
void init_client(const std::string &ip_address, uint16_t port)
void init_server(uint16_t port)
void shutdown_socket()
std::optional< json > recv_json()
void init_socket(uint16_t port)
void close_socket()