Hi all, I am attempting to build a simple socket connection into UE4.11.
I have this code, based on many hours internet trawling:
void UMyfTCPObject::Connect()
{
UE_LOG(LogTemp, Warning, TEXT("ConnectionManager::Init"));
FSocket* Socket = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateSocket(NAME_Stream, TEXT("default"), true);
FString address = TEXT("localhost");
int32 port = 19834;
TSharedRef<FInternetAddr> addr = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr();
addr->SetAnyAddress();
// addr->SetIp("127.0.0.1");
addr->SetPort(port);
UE_LOG(LogTemp, Warning, TEXT("Socket created! Connecting to server..."));
bool didConnect = Socket->Connect(*addr);
if (didConnect)
{
UE_LOG(LogTemp, Warning, TEXT("Connection state: true"));
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Connection state: false"));
}
}
But it will not connect. Always jumping to “Connection state: false”.
Does this look correct? Or have I gone terribly wrong?
Thank you!