Hello!
Setup: Unreal Engine 5.4.4 built from source on ubuntu 22.04.
I noticed one thing working with FSockets:
whenever I call GetConnectionState() it always returns ESocketConnectionState::SCS_Connected
I found similar topics:
And the fix is quite small: remove ‘readstate’ check inside GetConnectionState() source code:
https://github.com/EpicGames/UnrealEngine/pull/2882
But this PR did not fix my issue. I added few log lines in the ESocketConnectionState FSocketBSD::GetConnectionState(void):
ESocketConnectionState FSocketBSD::GetConnectionState(void)
{
ESocketConnectionState CurrentState = SCS_ConnectionError;
// look for an existing error
if (Socket != INVALID_SOCKET && HasState(ESocketBSDParam::HasError) == ESocketBSDReturn::No)
{
UE_LOG(LogTemp, Log, TEXT("FPlatformTime::Seconds() %f LastActivityTime %f delta: %f"),
FPlatformTime::Seconds(), LastActivityTime.load(), FPlatformTime::Seconds() - LastActivityTime.load());
if (FPlatformTime::Seconds() - LastActivityTime > 5.0)
{
// get the write state
ESocketBSDReturn WriteState = HasState(ESocketBSDParam::CanWrite, FTimespan::FromMilliseconds(1));
// ESocketBSDReturn ReadState = HasState(ESocketBSDParam::CanRead, FTimespan::FromMilliseconds(1));
// translate yes or no (error is already set)
if (WriteState == ESocketBSDReturn::Yes)
{
UE_LOG(LogTemp, Log, TEXT("WriteState == Yes"));
CurrentState = SCS_Connected;
LastActivityTime = FPlatformTime::Seconds();
}
else if (WriteState == ESocketBSDReturn::No)
{
UE_LOG(LogTemp, Log, TEXT("WriteState == No"));
CurrentState = SCS_NotConnected;
}
}
else
{
CurrentState = SCS_Connected;
}
}
return CurrentState;
}
And found out that when I had just created a socket:
ClientSocket = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateSocket(NAME_Stream, ClientSocketName, false);
it already returns SCS_Connected, and the function HasState already returns ESocketBSDReturn::Yes, though it hasn’t been connected to client yet.
[2025.02.27-08.25.04:001][575]LogTemp: WriteState == Yes
Has anyone encountered anything like this on UE 5.4.4? Are there any fixes? Or did I just misunderstand something.