FSocket Fails to Bind

Darkpyro2
Sun, 20 Dec 2020 01:16:04 +0000
Character & Animation

I am attempting to communicate between Unreal and another process using the FSocket socket programming API provided by Unreal. Here is my code:

//Networking configuration
	FIPv4Address ip(127, 0, 0, 1);
	Socket = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateSocket(NAME_Stream, TEXT("default"), false);
	TSharedRef<FInternetAddr> addr = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr();
	addr->SetIp(ip.Value);
	addr->SetPort(port);


	if (Socket->Bind(*addr)) {
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Bind Successful!"));

	}
	else {
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Bind Not Successful!"));
	}

The output generated is “Bind Not Successful!”, meaning that my call to Bind() is failing.

What could I be doing wrong here?

My intent is to listen on the loopback address. The selected port is 50323.

1 post - 1 participant