Network code documentation for my turn-based game 1.0
Loading...
Searching...
No Matches
server_network_manager.h
Go to the documentation of this file.
1#pragma once
2
3#include "types.h"
5
6#include <SFML/Network/TcpSocket.hpp>
7#include <SFML/Network/TcpListener.hpp>
8#include <SFML/Network/SocketSelector.hpp>
9
10#include <memory>
11
17public:
18 constexpr explicit ServerNetworkManager() noexcept = default;
19 constexpr ServerNetworkManager(ServerNetworkManager&& other) noexcept = delete;
20 constexpr ServerNetworkManager& operator=(ServerNetworkManager&& other)
21 noexcept = delete;
22 constexpr ServerNetworkManager(const ServerNetworkManager& other) noexcept = delete;
23 constexpr ServerNetworkManager& operator=(const ServerNetworkManager& other)
24 noexcept = delete;
25 ~ServerNetworkManager() noexcept override = default;
26
27 [[nodiscard]] ReturnStatus ListenToPort(Port port) noexcept;
28 void SendPacket(sf::Packet* packet, Port client_port) noexcept override;
29 void PollEvents() noexcept override;
30
31private:
32 void PollClientsConnections() noexcept;
33 void PollClientsPackets() noexcept;
34 void RemoveClient(std::unique_ptr<sf::TcpSocket>& client) noexcept;
35
36 std::vector<std::unique_ptr<sf::TcpSocket>> clients_{};
37 sf::SocketSelector socket_selector_{};
38 sf::TcpListener listener_{};
39};
ServerNetworkInterface is an interface to communicates with multiple clients.
Definition server_network_interface.h:11
ServerNetworkManager is an implementation of the NetworkInterface which manages network communication...
Definition server_network_manager.h:16
void SendPacket(sf::Packet *packet, Port client_port) noexcept override
constexpr ServerNetworkManager() noexcept=default
void PollEvents() noexcept override
PollEvents is a pure virtual method which must poll the network events such as client connections/dis...
ReturnStatus ListenToPort(Port port) noexcept
std::uint16_t Port
Definition types.h:19
ReturnStatus
Definition types.h:6