Jazz2::Multiplayer::NetworkManagerBase class

Allows to create generic network clients and servers.

Base classes

class Death::IDisposable
Base interface for releasing resources on object destruction.

Derived classes

class NetworkManager
Manages game-specific network connections.

Public static functions

static auto AddressToString(const struct in_addr& address, std::uint16_t port = 0) -> String
Converts the specified IPv4 endpoint to the string representation.
static auto AddressToString(const struct in6_addr& address, std::uint16_t port = 0) -> String
Converts the specified IPv6 endpoint to the string representation.
static auto AddressToString(const Peer& peer) -> String
Converts the endpoint of the specified peer to the string representation.

Constructors, destructors, conversion operators

NetworkManagerBase()
~NetworkManagerBase()
NetworkManagerBase(const NetworkManagerBase&) deleted

Public functions

auto operator=(const NetworkManagerBase&) -> NetworkManagerBase& deleted
void CreateClient(INetworkHandler* handler, StringView endpoints, std::uint16_t defaultPort, std::uint32_t clientData) virtual
Creates a client connection to a remote server.
auto CreateServer(INetworkHandler* handler, std::uint16_t port) -> bool virtual
Creates a server that accepts incoming connections.
void Dispose() virtual
Disposes all active connections.
auto GetState() const -> NetworkState
Returns state of network connection.
auto GetRoundTripTimeMs() const -> std::uint32_t
Returns mean round trip time to the server, in milliseconds.
auto GetServerEndpoints() const -> Array<String>
Returns all IPv4 and IPv6 addresses along with ports of the server.
void SendTo(const Peer& peer, NetworkChannel channel, std::uint8_t packetType, ArrayView<const std::uint8_t> data)
Sends a packet to a given peer.
void SendTo(Function<bool(const Peer&)>&& predicate, NetworkChannel channel, std::uint8_t packetType, ArrayView<const std::uint8_t> data)
Sends a packet to all connected peers that match a given predicate.
void SendTo(AllPeersT, NetworkChannel channel, std::uint8_t packetType, ArrayView<const std::uint8_t> data)
Sends a packet to all connected peers or the remote server peer.
void Kick(const Peer& peer, Reason reason)
Kicks a given peer from the server.

Protected functions

auto OnPeerConnected(const Peer& peer, std::uint32_t clientData) -> ConnectionResult virtual
Called when a peer connects to the local server or the local client connects to a server.
void OnPeerDisconnected(const Peer& peer, Reason reason) virtual
Called when a peer disconnects from the local server or the local client disconnects from a server.

Constants

static std::uint32_t MaxPeerCount constexpr
Maximum connected peer count.