|
Network Library Documentation
|
NetworkMonitor is responsible for actively monitoring network quality metrics such as latency, jitter, packet loss, bandwidth, and throughput. It provides real-time updates to the UI. More...
Public Member Functions | |
| void | OnPingResponse (int id) |
| Handles a received ping response, calculates latency and jitter in ms. | |
| void | StartBandwidthTest () |
| Initiates a bandwidth test by sending a large byte array. | |
| void | StartThroughputTest () |
| Starts a throughput test by sending 100 UDP packets. | |
| void | OnThroughputResposne (int pcktId, int DataSize) |
| Called when a response for a throughput packet is received. | |
| float | GetLossPercent () |
| float | GetAverageRTT () |
| float | GetJitter () |
Private Member Functions | |
| void | Start () |
| Subscribes to client events and starts monitoring after connection. | |
| void | StartMonitor () |
| Starts the latency monitor coroutine. | |
| void | StopMonitoring () |
| Stops all monitoring coroutines and cleanups. | |
| IEnumerator | PingCoroutine () |
| Coroutine that repeatedly sends latency packets and calculate packet loss. | |
| void | SendPing () |
| Sends a latency packet and tracks its send time. | |
| void | CalculateLoss () |
| Calculates packet loss percentage and updates the UI. | |
| void | CleanOldPings () |
| Removes pings that have exceeded the timeout. | |
| float | Average (List< float > list) |
| Calculates the average of values in float list. | |
| float | CalculateJitter () |
| Calculates jitter based on differences in RTT samples. | |
| void | OnBandwidthResponse () |
| Called when the server replies to a bandwidth test; calculates and displays bandwidth. | |
| IEnumerator | stopThroughput () |
| Coroutine that stops the throughput test after a fixed time - 5s if not completed. | |
| void | ThroughputCalculate () |
| Finalizes throughput test and updates the UI with results. | |
Private Attributes | |
| float | pingInterval = 1f |
| Interval in seconds between pings sent to measure latency. | |
| float | pingTimeout = 5f |
| Timeout in seconds after which a ping is considered lost. | |
| Text | MonitorText1 |
| UI Text element displaying packet loss, average latency, and jitter. | |
| Text | MonitorText2 |
| UI Text element displaying bandwidth test result. | |
| Text | MonitorText3 |
| UI Text element displaying throughput test result. | |
| int | sentPackets = 0 |
| Total number of latency packets sent. | |
| int | receivedResponses = 0 |
| Total number of latency responses received. | |
| int | sentPacketsInterval = 0 |
| Number of latency packets sent during the current interval. | |
| int | receivedResponsesInterval = 0 |
| Number of responses received during the current interval. | |
| HashSet< int > | awaitingResponses = new() |
| Set of IDs for which responses are still pending. | |
| Dictionary< int, float > | sentTimes = new() |
| Dictionary storing the send time for each packet ID. | |
| List< float > | latencySamples = new() |
| List of recent round-trip time (RTT) samples for calculating average latency and jitter. | |
| float | lastLossPercent = 0f |
| Last calculated packet loss percentage. | |
| float | lastJitter = 0f |
| Last calculated jitter value. | |
| float | bandwidthClientStartTime |
| Timestamp when the bandwidth test started. | |
| int | BandwidthDataSize |
| Size in bytes of the bandwidth test data. | |
| Coroutine | pingCoroutine |
| Coroutine reference for the ping routine. | |
| Coroutine | throughputTimeoutRoutine |
| Coroutine reference for the throughput timeout logic. | |
| float | ThroughputStartTime |
| int | ThroughputSentSize = 0 |
| int | ThroughputReceivedSize = 0 |
| bool | isThroughputRunning = false |
| int | ThroughputPacketsReceived = 0 |
NetworkMonitor is responsible for actively monitoring network quality metrics such as latency, jitter, packet loss, bandwidth, and throughput. It provides real-time updates to the UI.
Definition at line 10 of file NetworkMonitor.cs.
|
private |
Calculates the average of values in float list.
Definition at line 208 of file NetworkMonitor.cs.
|
private |
Calculates jitter based on differences in RTT samples.
Definition at line 218 of file NetworkMonitor.cs.
|
private |
Calculates packet loss percentage and updates the UI.
Definition at line 165 of file NetworkMonitor.cs.
|
private |
Removes pings that have exceeded the timeout.
Definition at line 192 of file NetworkMonitor.cs.
| float NetworkMonitor.GetAverageRTT | ( | ) |
Definition at line 324 of file NetworkMonitor.cs.
| float NetworkMonitor.GetJitter | ( | ) |
Definition at line 334 of file NetworkMonitor.cs.
| float NetworkMonitor.GetLossPercent | ( | ) |
Definition at line 320 of file NetworkMonitor.cs.
|
private |
Called when the server replies to a bandwidth test; calculates and displays bandwidth.
Definition at line 242 of file NetworkMonitor.cs.
| void NetworkMonitor.OnPingResponse | ( | int | id | ) |
Handles a received ping response, calculates latency and jitter in ms.
Definition at line 146 of file NetworkMonitor.cs.
| void NetworkMonitor.OnThroughputResposne | ( | int | pcktId, |
| int | DataSize ) |
Called when a response for a throughput packet is received.
Definition at line 287 of file NetworkMonitor.cs.
|
private |
Coroutine that repeatedly sends latency packets and calculate packet loss.
Definition at line 121 of file NetworkMonitor.cs.
|
private |
Sends a latency packet and tracks its send time.
Definition at line 134 of file NetworkMonitor.cs.
|
private |
Subscribes to client events and starts monitoring after connection.
Definition at line 94 of file NetworkMonitor.cs.
| void NetworkMonitor.StartBandwidthTest | ( | ) |
Initiates a bandwidth test by sending a large byte array.
Definition at line 230 of file NetworkMonitor.cs.
|
private |
Starts the latency monitor coroutine.
Definition at line 105 of file NetworkMonitor.cs.
| void NetworkMonitor.StartThroughputTest | ( | ) |
Starts a throughput test by sending 100 UDP packets.
Definition at line 258 of file NetworkMonitor.cs.
|
private |
Stops all monitoring coroutines and cleanups.
Definition at line 112 of file NetworkMonitor.cs.
|
private |
Coroutine that stops the throughput test after a fixed time - 5s if not completed.
Definition at line 301 of file NetworkMonitor.cs.
|
private |
Finalizes throughput test and updates the UI with results.
Definition at line 311 of file NetworkMonitor.cs.
|
private |
Set of IDs for which responses are still pending.
Definition at line 51 of file NetworkMonitor.cs.
|
private |
Timestamp when the bandwidth test started.
Definition at line 71 of file NetworkMonitor.cs.
|
private |
Size in bytes of the bandwidth test data.
Definition at line 75 of file NetworkMonitor.cs.
|
private |
Definition at line 253 of file NetworkMonitor.cs.
|
private |
Last calculated jitter value.
Definition at line 67 of file NetworkMonitor.cs.
|
private |
Last calculated packet loss percentage.
Definition at line 63 of file NetworkMonitor.cs.
|
private |
List of recent round-trip time (RTT) samples for calculating average latency and jitter.
Definition at line 59 of file NetworkMonitor.cs.
|
private |
UI Text element displaying packet loss, average latency, and jitter.
Definition at line 23 of file NetworkMonitor.cs.
|
private |
UI Text element displaying bandwidth test result.
Definition at line 27 of file NetworkMonitor.cs.
|
private |
UI Text element displaying throughput test result.
Definition at line 31 of file NetworkMonitor.cs.
|
private |
Coroutine reference for the ping routine.
Definition at line 79 of file NetworkMonitor.cs.
|
private |
Interval in seconds between pings sent to measure latency.
Definition at line 15 of file NetworkMonitor.cs.
|
private |
Timeout in seconds after which a ping is considered lost.
Definition at line 19 of file NetworkMonitor.cs.
|
private |
Total number of latency responses received.
Definition at line 39 of file NetworkMonitor.cs.
|
private |
Number of responses received during the current interval.
Definition at line 47 of file NetworkMonitor.cs.
|
private |
Total number of latency packets sent.
Definition at line 35 of file NetworkMonitor.cs.
|
private |
Number of latency packets sent during the current interval.
Definition at line 43 of file NetworkMonitor.cs.
|
private |
Dictionary storing the send time for each packet ID.
Definition at line 55 of file NetworkMonitor.cs.
|
private |
Definition at line 254 of file NetworkMonitor.cs.
|
private |
Definition at line 252 of file NetworkMonitor.cs.
|
private |
Definition at line 251 of file NetworkMonitor.cs.
|
private |
Definition at line 250 of file NetworkMonitor.cs.
|
private |
Coroutine reference for the throughput timeout logic.
Definition at line 83 of file NetworkMonitor.cs.