Skip to main content

NetworkManager

A static class in Root.Township, Alta.Networking.

Static owner of the network transport (KCP) and all sockets. Pumps receiving in Update and sending in LateUpdate, and keeps packet and error counters for profiling.

Fields​

MemberWhat it is
static bool IsTransportStartedWhether the transport and update loops have started.
static AverageNumber ReceivingMsAverage time spent receiving per frame.
static AverageNumber SendingMsAverage time spent sending per frame.
static ITransport TransportThe transport in use, created on first socket.
9 private and internal fields
MemberWhat it is
private static Logger loggerLogger for this class.
private static IUnityUpdateMethod receiveUpdate handle cleared by Terminate; never set, so Terminate does not stop Receive.
private static IUnityUpdateMethod receiveUpdateMethodUpdate handle for Receive.
private static readonly UpdateModule receivingModuleUpdate module (Update) that runs Receive, included in server profiling.
private static IUnityUpdateMethod sendUpdate handle cleared by Terminate; never set, so Terminate does not stop Send.
private static readonly UpdateModule sendingModuleUpdate module (LateUpdate) that runs Send, included in server profiling.
private static IUnityUpdateMethod sendUpdateMethodUpdate handle for Send.
private static readonly List<ISocket> socketsAll open sockets, updated each frame.
private static readonly Stopwatch timerStopwatch used to time send and receive.

Properties​

MemberWhat it is
static ulong AltaNetworkError_Congestion { get; set; }Count of congestion errors from the transport.
static ulong AltaNetworkError_ConnectionClosed { get; set; }Count of connection closed errors.
static ulong AltaNetworkError_DnsResolve { get; set; }Count of DNS errors.
static ulong AltaNetworkError_InvalidReceive { get; set; }Count of invalid receive errors.
static ulong AltaNetworkError_InvalidSend { get; set; }Count of invalid send errors.
static ulong AltaNetworkError_None { get; set; }Count of errors reported with code None.
static ulong AltaNetworkError_Timeout { get; set; }Count of timeout errors.
static ulong AltaNetworkError_Unexpected { get; set; }Count of unexpected errors.
static ulong AltaNetworkError_WrongConnection { get; set; }Count of wrong connection errors.
static ulong FailedPackets { get; set; }Sends the transport refused.
static ulong FloodedPackets { get; set; }Sends dropped because the transport connection was flooded.
static ulong QueueLimitPackets { get; set; }Sends dropped because the server or connection queue limit was hit.
static ulong ReliablePacketOverflowDisconnects { get; set; }Disconnects caused by too many queued reliable packets.
static ulong SentPackets { get; set; }Packets sent successfully.
1 private and internal property
MemberWhat it is
private static NetworkingSettings Settings { get; }The global NetworkingSettings.

Methods​

MemberWhat it is
static void CloseSocket(ISocket socket)Removes and disposes a socket.
static ISocket CreateSocket(bool isServer, TransportSystem transportSystem, int socketPort = 0)Starts the transport if needed and creates a socket (server sockets on the given port).
static void Terminate()Disposes every socket and shuts the transport down.
6 private and internal methods
MemberWhat it is
private static void CreateTransport()Creates the transport from NetworkingSettings; only KCP is supported, anything else throws.
private static void EnsureNetworkingHasStarted()On first use, creates the transport, its channels and the send and receive update calls.
private static void Receive()Each Update, runs every socket's receive and records the time in ReceivingMs.
private static void Send()Each LateUpdate, runs every socket's send and records the time in SendingMs.
private static void SetupSendReceive(Connection _ = null)Registers Receive and Send on their update modules, replacing any earlier registration.
private static void SetupTransportChannels()Creates a transport channel for each channel in the settings.