Announcement

Collapse
No announcement yet.

Udp receivre

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    Udp receivre

    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\n"), BytesRead);
    }

    }

    the log is published but the bytesRead is always 0, someone can help ?

    #2
    Do you ever send anything to the socket? It sounds like it's working fine, but that there just isn't any data to read.

    Also, are you sure you bind the socket in Tick? That seems like it'd be a one-time thing in BeginPlay, and then you just read from the socket multiple times later.

    Comment


      #3
      hi nilamo
      it's was about binding the socket and setting up the endpoint
      here the example that i used to solve the problem
      https://forums.unrealengine.com/comm...iving-tutorial

      Comment

      Working...
      X