This function returns network status information.
table getNetworkStats ( )
table getNetworkStats ( [ element thePlayer = nil ] )
- thePlayer: The player you want to retrieve network stats from.
Returns a table, the indexes in the table are the following:
- bytesReceived - Total number of bytes received since the connection was started
- bytesSent - Total number of bytes sent since the connection was started
- packetsReceived - Total number of packets received since the connection was started
- packetsSent - Total number of packets sent since the connection was started
- packetlossTotal - (0-100) Total packet loss percentage of sent data, since the connection was started
- packetlossLastSecond - (0-100) Packet loss percentage of sent data, during the previous second
- messagesInResendBuffer - Number of packets queued to be resent (due to packet loss)
This example outputs the local players network status information to their console when using the /netstatus command
function netStatus() for index, value in pairs(getNetworkStats()) do outputConsole(index..": "..value) end outputChatBox("Network status output to console", 0, 255, 0) end addCommandHandler("netstatus", netStatus)
This example outputs a warning to local player if packet loss occured in the last second
function packetLossCheck() local loss = getNetworkStats()["packetlossLastSecond"] if (loss > 0) then outputChatBox("Packet loss detected when communicating with server, gameplay may be affected", 255, 0, 0) end end setTimer(packetLossCheck, 1000, 0)