UDP socket listener

Hello there !

i got some trouble to make my udp socket working, as a local server -> client it works perfect but when i switch to my public IP i can’t receive anything,

I’m using the last 4.10 rev.

here is my socket:



FIPv4Address ip;
FIPv4Address::Parse(ips, ip);
addr.Add(ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr());
addr[0]->SetIp(ip.GetValue());
addr[0]->SetPort(port);
client = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateSocket(NAME_DGram, TEXT("MySuperUdpSocket"));
client->SetNonBlocking(true);


i’m using a list to store my TSharedRef or i can’t define it in the .H but this is not the problem.

my recv function look like this in the client:


uint32 PendingData;
	client->HasPendingData(PendingData);
	if (PendingData > 0)
	{
		NtlPAcket *pk = new NtlPAcket;
		int32 BytesRead;

		client->Recv((uint8*)pk, PendingData, BytesRead);
		if (pk)
		{
			if (ThePC)
			{
				ThePC->parseMyPacket(pk);
			}
		}
	}

So, is a way with UE4 and udp to make a socket to send and one to recv ? yes there is but i can’t figure it out:


receiver = FUdpSocketBuilder(TEXT("RECVER"))
		.AsNonBlocking()
		.AsReusable()
		.BoundToAddress(ip);
		.BoundToPort(7777)
		.Build();
	return receiver->Listen(50);


uint32 PendingData;
	receiver->HasPendingData(PendingData);
	if (PendingData > 0)
	{
		NtlPAcket *pk = new NtlPAcket;
		int32 BytesRead;

		receiver->Recv((uint8*)pk, PendingData, BytesRead);
		if (pk)
		{
			if (ThePC)
			{
				ThePC->parseMyPacket(pk);
			}
		}
	}


If anyone have a solution to let me use a udp socket receiver with a public IP !!

Thank you :).

I changed some thing into my Class but still the same, my socket won’t listen, HasPendingData() is never ok.



receiver = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateSocket(NAME_DGram, TEXT("MySuperSocketUdpBis"), true);
	bool Error = !receiver->SetNonBlocking(true) || !receiver->SetRecvErr();
	if (!Error)
	{
		FIPv4Address RemoteAdressBind;
		FIPv4Address::Parse("127.0.0.1", RemoteAdressBind);
		FIPv4Endpoint RemoteEndPointBind = FIPv4Endpoint(RemoteAdressBind, 7777);
		int32 OutNewSize;

		int size = sizeof(NtlPAcket);
		receiver->SetReceiveBufferSize(size, OutNewSize);
		receiver->SetSendBufferSize(size, OutNewSize);
		if ((receiver->Listen(10)) == false) <-------- STILL GETTING FALSE
			UE_LOG(LogInit, Log, TEXT("FUdpSocketBuilder: receiver listen error"));
		bool errors = receiver->Bind(*RemoteEndPointBind.ToInternetAddr());
		if (errors == false)
		{
			UE_LOG(LogInit, Log, TEXT("FUdpSocketBuilder: Failed to create the socket %s as configured receiver"), TEXT("MySuperSocketUdpBis"));
		}
		else
		{
			UE_LOG(LogInit, Log, TEXT("FUdpSocketBuilder: RECEIVER BINDED"));  <-------- OK NOW
		}



Okayyyyyy i’m so stupide, i fixed it…


receiver->Recv((uint8*)pk, PendingData, BytesRead); 

I’m using TCP recv


receiver->RecvFrom((uint8*)pk, PendingData, BytesRead, *RemoteEndPoint.ToInternetAddr()); 

By UDP it is working like a charm recvfrom