ConnectionRetryDelay

ConnectionRetryDelay

#Overview

name: ConnectionRetryDelay

The value of this variable can be defined or overridden in .ini config files. 2 .ini config files referencing this setting variable.

It is referenced in 15 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of ConnectionRetryDelay is to control the time interval between connection retry attempts in network-related components of Unreal Engine 5. This setting variable is primarily used in network communication and messaging systems to manage reconnection behavior when a connection fails or is lost.

The ConnectionRetryDelay variable is utilized in the following Unreal Engine subsystems and modules:

  1. StormSync Transport Client Plugin
  2. TcpMessaging Plugin

The value of this variable is typically set in configuration files or through the UStormSyncTransportSettings and UTcpMessagingSettings classes. It can be accessed using getter methods like GetConnectionRetryDelay().

This variable interacts with other network-related variables, such as ConnectionRetryPeriod, which determines the overall duration for retry attempts.

Developers should be aware of the following when using this variable:

  1. Setting ConnectionRetryDelay to 0 typically disables automatic reconnection attempts.
  2. The value is used in sleep functions, so it directly affects the responsiveness of the reconnection process.
  3. It’s used in both client-side and server-side connection management.

Best practices for using this variable include:

  1. Choose an appropriate delay value that balances quick reconnection with avoiding network congestion.
  2. Consider the specific requirements of your game or application when setting this value.
  3. Use it in conjunction with ConnectionRetryPeriod for more granular control over reconnection behavior.
  4. Monitor and log connection attempts to help diagnose network issues.
  5. Allow this value to be configurable, enabling adjustments without code changes.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Config/BaseEngine.ini:3364, section: [/Script/TcpMessaging.TcpMessagingSettings]

Location: <Workspace>/Engine/Config/Android/AndroidEngine.ini:48, section: [/Script/TcpMessaging.TcpMessagingSettings]

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Plugins/Experimental/StormSync/Source/StormSyncTransportClient/Private/Socket/StormSyncTransportClientSocket.cpp:19

Scope (from outer to inner):

file
function     FStormSyncTransportClientSocket::FStormSyncTransportClientSocket

Source code excerpt:

{
	Settings = GetDefault<UStormSyncTransportSettings>();
	ConnectionRetryDelay = Settings->GetConnectionRetryDelay();
}

FStormSyncTransportClientSocket::~FStormSyncTransportClientSocket()
{
	UE_LOG(LogStormSyncClient, Display, TEXT("FStormSyncTransportClientSocket::~FStormSyncTransportClientSocket Destructor Closing socket and runnable to '%s'"), *RemoteEndpoint.ToString());
	

#Loc: <Workspace>/Engine/Plugins/Experimental/StormSync/Source/StormSyncTransportClient/Private/Socket/StormSyncTransportClientSocket.cpp:135

Scope (from outer to inner):

file
function     uint32 FStormSyncTransportClientSocket::Run

Source code excerpt:

		);

		if (!bListenerIsRunning && GetConnectionState() == State_Closed && ConnectionRetryDelay > 0)
		{
			bListenerIsRunning = TryReconnect();
		}

		if (!bListenerIsRunning)
		{

#Loc: <Workspace>/Engine/Plugins/Experimental/StormSync/Source/StormSyncTransportClient/Private/Socket/StormSyncTransportClientSocket.cpp:250

Scope (from outer to inner):

file
function     bool FStormSyncTransportClientSocket::TryReconnect

Source code excerpt:

		}
    
		FPlatformProcess::Sleep(ConnectionRetryDelay);

		bReconnectPending = Connect();
		if (bReconnectPending)
		{
			ConnectionState = State_DisconnectReconnectPending;
		}

#Loc: <Workspace>/Engine/Plugins/Experimental/StormSync/Source/StormSyncTransportClient/Private/Socket/StormSyncTransportClientSocket.h:211

Scope (from outer to inner):

file
class        class FStormSyncTransportClientSocket : public FRunnable, public TSharedFromThis<FStormSyncTransportClientSocket>

Source code excerpt:


	/** Delay before re-establishing connection if it drops, 0 disables */
	uint32 ConnectionRetryDelay;

	/** Delegate trigger when underlying socket is closed */
	FStormSyncOnConnectionClosed ConnectionClosedDelegate;
	
	/** Connection state changed delegate */
	FStormSyncOnConnectionStateChanged ConnectionStateChangedDelegate;

#Loc: <Workspace>/Engine/Plugins/Experimental/StormSync/Source/StormSyncTransportCore/Private/StormSyncTransportSettings.cpp:86

Scope (from outer to inner):

file
function     uint32 UStormSyncTransportSettings::GetConnectionRetryDelay

Source code excerpt:

uint32 UStormSyncTransportSettings::GetConnectionRetryDelay() const
{
	return ConnectionRetryDelay;
}

bool UStormSyncTransportSettings::HasConnectionRetryDelay() const
{
	return ConnectionRetryDelay > 0;
}

FString UStormSyncTransportSettings::GetServerName() const
{
	return ServerName;
}

#Loc: <Workspace>/Engine/Plugins/Experimental/StormSync/Source/StormSyncTransportCore/Public/StormSyncTransportSettings.h:147

Scope (from outer to inner):

file
class        class UStormSyncTransportSettings : public UDeveloperSettings

Source code excerpt:

	 */
	UPROPERTY(config, EditAnywhere, Category = "Client")
	uint32 ConnectionRetryDelay = 0;

	/** The refresh frequency of the heartbeat event */
	UPROPERTY(config, EditAnywhere, AdvancedDisplay, Category = "Service Discovery", meta=(ClampMin = "0.1", ConfigRestartRequired=true, ForceUnits=s))
	float MessageBusHeartbeatPeriod = 1.f;

	/** How long we should wait before checking for message bus sources activity */

#Loc: <Workspace>/Engine/Plugins/Messaging/TcpMessaging/Source/TcpMessaging/Private/Settings/TcpMessagingSettings.h:59

Scope (from outer to inner):

file
class        class UTcpMessagingSettings : public UObject

Source code excerpt:

	 */
	UPROPERTY(config, EditAnywhere, Category = Transport)
	int32 ConnectionRetryDelay;

	/**
	 * Period time during which attempts to re-establish outgoing connections that become disconnected or fail to connect
	 * 0 means it will be retried only once
	 */
	UPROPERTY(config, EditAnywhere, Category = Transport)

#Loc: <Workspace>/Engine/Plugins/Messaging/TcpMessaging/Source/TcpMessaging/Private/TcpMessagingModule.cpp:378

Scope (from outer to inner):

file
function     int32 UTcpMessagingSettings::GetConnectionRetryDelay

Source code excerpt:

int32 UTcpMessagingSettings::GetConnectionRetryDelay() const
{
	return ConnectionRetryDelay;
}

int32 UTcpMessagingSettings::GetConnectionRetryPeriod() const
{
	return ConnectionRetryPeriod;
}

#Loc: <Workspace>/Engine/Plugins/Messaging/TcpMessaging/Source/TcpMessaging/Private/Transport/TcpMessageTransport.cpp:18

Scope (from outer to inner):

file
function     FTcpMessageTransport::FTcpMessageTransport

Source code excerpt:

	: ListenEndpoint(InListenEndpoint)
	, ConnectToEndpoints(InConnectToEndpoints)
	, ConnectionRetryDelay(InConnectionRetryDelay)
	, ConnectionRetryPeriod(InConnectionRetryPeriod)
	, bStopping(false)
	, SocketSubsystem(ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM))
	, Listener(nullptr)
	, TransportHandler(nullptr)
{

#Loc: <Workspace>/Engine/Plugins/Messaging/TcpMessaging/Source/TcpMessaging/Private/Transport/TcpMessageTransport.cpp:80

Scope (from outer to inner):

file
function     void FTcpMessageTransport::AddOutgoingConnection

Source code excerpt:

	else
	{
		PendingConnections.Enqueue(MakeShareable(new FTcpMessageTransportConnection(Socket, Endpoint, ConnectionRetryDelay, ConnectionRetryPeriod)));
	}
}

void FTcpMessageTransport::RemoveOutgoingConnection(const FIPv4Endpoint& Endpoint)
{
	ConnectionEndpointsToRemove.Enqueue(Endpoint);

#Loc: <Workspace>/Engine/Plugins/Messaging/TcpMessaging/Source/TcpMessaging/Private/Transport/TcpMessageTransport.h:94

Scope (from outer to inner):

file
class        class FTcpMessageTransport : FRunnable , public IMessageTransport

Source code excerpt:

	FIPv4Endpoint ListenEndpoint;
	TArray<FIPv4Endpoint> ConnectToEndpoints;
	int32 ConnectionRetryDelay;
	int32 ConnectionRetryPeriod;

	/** For the thread */
	bool bStopping;
	
	/** Holds a pointer to the socket sub-system. */

#Loc: <Workspace>/Engine/Plugins/Messaging/TcpMessaging/Source/TcpMessaging/Private/Transport/TcpMessageTransportConnection.cpp:69

Scope (from outer to inner):

file
function     FTcpMessageTransportConnection::FTcpMessageTransportConnection

Source code excerpt:

	, TotalBytesSent(0)
	, bRun(false)
	, ConnectionRetryDelay(InConnectionRetryDelay)
	, ConnectionRetryPeriod(InConnectionRetryPeriod)
	, RecvMessageDataRemaining(0)
{
	int32 NewSize = 0;
	Socket->SetReceiveBufferSize(TCP_MESSAGING_RECEIVE_BUFFER_SIZE, NewSize);
	Socket->SetSendBufferSize(TCP_MESSAGING_SEND_BUFFER_SIZE, NewSize);

#Loc: <Workspace>/Engine/Plugins/Messaging/TcpMessaging/Source/TcpMessaging/Private/Transport/TcpMessageTransportConnection.cpp:172

Scope (from outer to inner):

file
function     uint32 FTcpMessageTransportConnection::Run

Source code excerpt:

		{
			// Disconnected. Reconnect if requested.
			const float Delay = ConnectionRetryDelay;
			if (Delay > 0)
			{
				bool bReconnectPending = false;
				{
				    // Wait for any sending before we close the socket
				    FScopeLock SendLock(&SendCriticalSection);

#Loc: <Workspace>/Engine/Plugins/Messaging/TcpMessaging/Source/TcpMessaging/Private/Transport/TcpMessageTransportConnection.cpp:187

Scope (from outer to inner):

file
function     uint32 FTcpMessageTransportConnection::Run

Source code excerpt:

					{
						UE_LOG(LogTcpMessaging, Verbose, TEXT("Connection to '%s' failed, retrying..."), *RemoteEndpoint.ToString());
						FPlatformProcess::Sleep(ConnectionRetryDelay);

						Socket = FTcpSocketBuilder(TEXT("FTcpMessageTransport.RemoteConnection"))
							.WithSendBufferSize(TCP_MESSAGING_SEND_BUFFER_SIZE)
							.WithReceiveBufferSize(TCP_MESSAGING_RECEIVE_BUFFER_SIZE);

						if (Socket && Socket->Connect(RemoteEndpoint.ToInternetAddr().Get()))

#Loc: <Workspace>/Engine/Plugins/Messaging/TcpMessaging/Source/TcpMessaging/Private/Transport/TcpMessageTransportConnection.h:215

Scope (from outer to inner):

file
class        class FTcpMessageTransportConnection : public FRunnable , public TSharedFromThis<FTcpMessageTransportConnection>

Source code excerpt:


	/** Delay before re-establishing connection if it drops, 0 disables */
	int32 ConnectionRetryDelay;

	/** Period during which re-establishing connection if it drops, 0 means it will retry only once */
	int32 ConnectionRetryPeriod;

	/** Message data we're currently in the process of receiving, if any */
	TSharedPtr<FArrayReader, ESPMode::ThreadSafe> RecvMessageData;