KeepAliveTime
KeepAliveTime
#Overview
name: KeepAliveTime
The value of this variable can be defined or overridden in .ini config files. 3
.ini config files referencing this setting variable.
It is referenced in 4
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of KeepAliveTime is to manage the frequency of network communication between the server and clients in Unreal Engine’s networking system. It is used to maintain an active connection and prevent timeouts by ensuring regular communication even when there’s no other data to send.
This setting variable is primarily used in the Unreal Engine’s networking subsystem, specifically within the NetDriver and NetConnection components. It’s also referenced in the OnlineSubsystemOculus plugin, indicating its relevance to VR networking.
The value of KeepAliveTime is set in the engine configuration files. It can be modified through project settings or config files.
KeepAliveTime interacts with other networking-related variables such as LastSendTime and InitialConnectTimeout. It’s used in conjunction with the Driver’s elapsed time to determine when to send keep-alive packets.
Developers must be aware that:
- Setting KeepAliveTime to 0 is not recommended, as the engine will automatically set it to a default value (0.2 seconds in the Oculus plugin).
- This variable affects network performance and bandwidth usage, so it should be tuned carefully based on the game’s requirements.
- It’s crucial for maintaining connections in high-latency or unreliable network environments.
Best practices when using this variable include:
- Set an appropriate value based on your game’s networking needs and target platforms.
- Monitor network performance and adjust KeepAliveTime if necessary.
- Consider different values for different network conditions (e.g., LAN vs. internet play).
- Be mindful of bandwidth usage, especially on mobile or limited network connections.
- Test thoroughly with various network conditions to ensure optimal performance.
#Setting Variables
#References In INI files
Location: <Workspace>/Engine/Config/BaseEngine.ini:1634, section: [/Script/OnlineSubsystemUtils.IpNetDriver]
- INI Section:
/Script/OnlineSubsystemUtils.IpNetDriver
- Raw value:
0.2
- Is Array:
False
Location: <Workspace>/Engine/Config/BaseEngine.ini:2261, section: [/Script/SteamSockets.SteamSocketsNetDriver]
- INI Section:
/Script/SteamSockets.SteamSocketsNetDriver
- Raw value:
0.2
- Is Array:
False
Location: <Workspace>/Engine/Plugins/Experimental/WebSocketNetworking/Config/BaseWebSocketNetDriver.ini:14, section: [/Script/WebSocketNetworking.WebSocketNetDriver]
- INI Section:
/Script/WebSocketNetworking.WebSocketNetDriver
- Raw value:
20.2
- Is Array:
False
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Plugins/Online/OnlineSubsystemOculus/Source/Private/OculusNetDriver.cpp:58
Scope (from outer to inner):
file
function bool UOculusNetDriver::InitBase
Source code excerpt:
}
if (KeepAliveTime == 0.0)
{
UE_LOG(LogNet, Warning, TEXT("KeepAliveTime was set to %f"), KeepAliveTime);
KeepAliveTime = 0.2;
}
if (SpawnPrioritySeconds == 0.0)
{
UE_LOG(LogNet, Warning, TEXT("SpawnPrioritySeconds was set to %f"), SpawnPrioritySeconds);
SpawnPrioritySeconds = 1.0;
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/Engine/NetDriver.h:890
Scope (from outer to inner):
file
class class UNetDriver : public UObject, public FExec
Source code excerpt:
/** @todo document */
UPROPERTY(Config)
float KeepAliveTime;
/** Amount of time to wait for a new net connection to be established before destroying the connection */
UPROPERTY(Config)
float InitialConnectTimeout;
/**
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetConnection.cpp:2121
Scope: file
Source code excerpt:
// If there is any pending data to send, send it.
if (SendBuffer.GetNumBits() || HasDirtyAcks || ( Driver->GetElapsedTime() - LastSendTime > Driver->KeepAliveTime && !IsInternalAck() && GetConnectionState() != USOCK_Closed))
{
// Due to the PacketHandler handshake code, servers must never send the client data,
// before first receiving a client control packet (which is taken as an indication of a complete handshake).
if (!HasReceivedClientPacket() && CVarRandomizeSequence.GetValueOnAnyThread() != 0)
{
UE_LOG(LogNet, Log, TEXT("Attempting to send data before handshake is complete. %s"), *Describe());
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/NetConnection.cpp:4597
Scope (from outer to inner):
file
function void UNetConnection::Tick
Source code excerpt:
// Flush.
if ( TimeSensitive || (Driver->GetElapsedTime() - LastSendTime) > Driver->KeepAliveTime)
{
bool bHandlerHandshakeComplete = !Handler.IsValid() || Handler->IsFullyInitialized();
// Delay any packet sends on the server, until we've verified that a packet has been received from the client.
if (bHandlerHandshakeComplete && HasReceivedClientPacket())
{