Hi all, I am trying to set up a simple TCP or UDP connection, to stream data into a game at runtime.
I have tried to use Rama’s code, from here:
A new, community-hosted Unreal Engine Wiki - Announcements and Releases - Unreal Engine Forums,Receive_Binary_Data_From_an_IP/Port_Into_UE4,(Full_Code_Sample)#.cpp
But every time I #include FIPv4Address.h, I get a million errors. Without it, i cannot use this code.
So, now I have:
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 = 8888;
TSharedRef<FInternetAddr> addr = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr();
// addr->SetAnyAddress();
addr->SetIp((ULONG)0x00000000);
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"));
uint8 Data[1024]; //buffer size
int32 byteCount = 0; //the number os bytes read
int32 dataSize = 0; //the size of the data
Socket->Recv(Data, dataSize, byteCount);
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, FString::FromInt(byteCount));
if (byteCount >= dataSize)
Socket->Recv(Data, byteCount, dataSize);
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Connection state: false"));
}
Socket->Close();
}
But it will not connect, jumping straight to ‘Connection state: false’.
Does anyone have any tips here?
Thanks!