Download

Android - Crash with TCP Code

It took me almost a month to run my project as an Android application.
It runs well as a Window program. Although the Android package was successful, the app crashed with start-up.

After a lot of trial and error, I realized that the TCP plugin(that I bought in Market) was the problem, and implemented the TCP function as a C++ class.
The same thing happened even though I wrote TCP in C++.
When I delayed the TCP transmission execution time by using TiCK function, Crashwas delayed using the TICK function, the time at which the app crashes is also delayed.

I’d appreciate it if you could let me know what I’m missing.

Below is my code.

#include "MyActor.h"
#include "Networking.h"
#include "Sockets.h"
#include "SocketSubsystem.h"
#include "IPAddress.h"
// Sets default values

AMyActor::AMyActor()
{
	nCount = 0;
	PrimaryActorTick.bCanEverTick = true;
}

void AMyActor::SendSomething()
{

	AsyncTask(ENamedThreads::GameThread, []()
		{

			ISocketSubsystem* SocketSubsystem = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM);

			FSocket* Socket = FTcpSocketBuilder(TEXT("Android Porting Test"));
			FIPv4Endpoint Endpoint(FIPv4Address(***, ***, ***, ***), 9999);

			if (Socket->Connect(*Endpoint.ToInternetAddr()))
			{
				//success
			}
			else
			{
				return;
			}

			char* buff = (char*)"Test2222";
			int32 sendSize = 0;
			Socket->Send((uint8*)buff, strlen(buff), sendSize);
			// Code placed here will run in the game thread

	});
}

// Called when the game starts or when spawned
void AMyActor::BeginPlay()
{
	Super::BeginPlay();

}

// Called every frame
void AMyActor::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	if (nCount == 10)
		SendSomething();
	else
		nCount++;
}

  • UE Version : 4.26