Hello i’m trying to receive message under udp protocol
After reading some tutorials and documentation, the code i use is :
#include “recv_messag.h”
#include “Networking.h”
#include “Engine.h”
// Sets default values
Arecv_messag::Arecv_messag()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don’t need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void Arecv_messag::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void Arecv_messag::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
TSharedRef<FInternetAddr> RemoteAddr = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr();
FString YourChosenSocketName = "namesocket";
FString TheIP = "127.0.0.1";
bool bIsValid;
RemoteAddr->SetIp(*TheIP, bIsValid);
RemoteAddr->SetPort(14442);
if (!bIsValid)
{
UE_LOG(LogTemp, Log, TEXT("IP address was not valid!"));
}
RecvSocket = FUdpSocketBuilder(*YourChosenSocketName)
.AsReusable()
.WithBroadcast()
;
int32 SendSize = 2 * 1024 * 1024;
RecvSocket->SetSendBufferSize(SendSize, SendSize);
RecvSocket->SetReceiveBufferSize(SendSize, SendSize);
if (!RecvSocket->Bind(*RemoteAddr))
{
UE_LOG(LogTemp, Log, TEXT("Socket not binding"));
}
int32 BytesRead;
uint8 Data;
if (RecvSocket->Recv(&Data, sizeof(Data), BytesRead))
{
UE_LOG(LogTemp, Log, TEXT("Socket not binding %d
"), BytesRead);
}
}
the log is published but the bytesRead is always 0, someone can help ?