Can i use FTcpListener ?

Hi all,

Looking for info about socket multithreading, i came accross this old answerhub post:

Anyone knows what’s the current FTcpListener code health ? Can it be used safely, will it be supported in the long term ?

Thanks !



I have been trying to use the FTcpListener without success.

I am stuck in an infinite while loop, namely the while(!Stopping) loop of line 149 in TcpListener.h. So it looks like this while loop is not threaded.

As this is engine code, i posted a question in answerhub in the bug section, but maybe i am just misusing it ?

Here is my code:

// Called when the game starts (gamestate's BeginPlay() function)
void UYagFileServer::Start()
	// server only
	if (FileServerGameState->Role < ROLE_Authority) return;

	// listening socket
	FIPv4Endpoint Endpoint(FIPv4Address(127, 0, 0, 1), UYagFileServer::YagServerPort);
	ListenerSocket = FTcpSocketBuilder("ServerListeningSocket")

	//Set Buffer Size
	int32 ReceiveBufferSize = 2 * 1024 * 1024;
	int32 NewSize = 0;
	ListenerSocket->SetReceiveBufferSize(ReceiveBufferSize, NewSize);

	YagTcpListener = new FTcpListener(*ListenerSocket);
	YagTcpListener->OnConnectionAccepted().BindUObject(this, &UYagFileServer::ListenToMessage);

	if (YagTcpListener->Init()) YagTcpListener->Run();

Anyone has some experience with the FTcpListener class ?



Ok, some progress, i didn’t know i didn’t need to call the run function, that’s why i got stuck^^


Try this:

FTcpListener* m_TCP_Listener;
FRunnableThread* m_Thread;

m_TCP_Listener = new FTcpListener(…);
m_TCP_Listener->OnConnectionAccepted().BindUObject(this, &…);

if (m_TCP_Listener->Init()) {
m_Thread = FRunnableThread::Create(m_TCP_Listener, TEXT(“TCP_Subsystem_Thread”), 0, TPri_BelowNormal);

1 Like