# FSocket-\>GetConnectionState() always return SCS\_Connected

**URL:** <https://forums.unrealengine.com/t/fsocket-getconnectionstate-always-return-scs-connected/2362308>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, question\
**Created:** [February 27, 2025, 8:43am UTC](https://forums.unrealengine.com/t/fsocket-getconnectionstate-always-return-scs-connected/2362308 "2025-02-27T08:43:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![seeyouantee](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/seeyouantee/32/88716_2.png) [@seeyouantee](https://forums.unrealengine.com/u/seeyouantee)\
**Post date:** [February 27, 2025, 8:43am UTC](https://forums.unrealengine.com/t/fsocket-getconnectionstate-always-return-scs-connected/2362308/1 "2025-02-27T08:43:40Z")

</div>

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:

> [@FSocket GetConnectionState always returns true](https://forums.unrealengine.com/t/fsocket-getconnectionstate-always-returns-true/345349/4):
>
> Hi, I have same issue. plz let me know if you found solution.

> [@FSocket::GetConnectionState return "Connected" after \*just\* created](https://forums.unrealengine.com/t/fsocket-getconnectionstate-return-connected-after-just-created/381425):
>
> I created the FSocket instance like below: FSocket\* Socket\_; Socket\_ = ISocketSubsystem::Get(PLATFORM\_SOCKETSUBSYSTEM)-\>CreateSocket(NAME\_Stream, TEXT("TestSocket"), false); and I tried to get the state of socket like below: ESocketConnectionState CurrentStatus = Socket\_-\>GetConnectionState(); It works fine at PIE. Editor. It returns ESocketConnectionState::SCS\_NotConnected but when it runs on android device, It returns ESocketConnectionState::SCS\_Connected. Does anyone have similar expe…

And the fix is quite small: remove ‘readstate’ check inside GetConnectionState() source code:  
[https://github.com/EpicGames/UnrealEngine/pull/2882](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)_:

```auto

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:

```auto
	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.
