UDP Socket: FUdpSocketBuilder Errors

Hello,

I have a Python UDP socket server listening for packets from the game, but the game client socket is not being created.

The Output Log errors are:

FUdpSocketBuilder: Failed to bind UpdSendSocket to 127.0.0.1:2345
FUdpSocketBuilder: Failed to configure multicast for UpdSendSocket (loopback: 0, ttl: 1)
FUdpSocketBuilder: Failed to create and initialize socket UpdSendSocket (last error: 0)

This is the code:

#define PORT 2345

FIPv4Endpoint EndPoint1(FIPv4Address(127, 0, 0, 1), PORT);

	FSocket *UdpSenderSocket = FUdpSocketBuilder(TEXT("UpdSendSocket"))
		.BoundToEndpoint(EndPoint1)
		.AsNonBlocking()
		.AsReusable()
		.WithBroadcast()
		.WithSendBufferSize(2 * 1024 * 1024);

Any suggestions? Thanks!

Adding these lines after FUdpSocketBuilder will crash the game:

int32 SendSize = 2 * 1024 * 1024;
UdpSenderSocket->SetSendBufferSize(SendSize, SendSize);

The MiniDump Exception reads: The thread tried to read from or write to a virtual address for which it does not have the appropriate access.

This same exception appears when a C++ WinSock with Select (a non-blocking socket) waits for dropped packets.

I figured it out. The Endpoint of FUdpSocketBuilder is the Client (game) IP/Port. The SendTo Endpoint is the Server IP/Port.

The error was caused by the Client’s socket endpoint being already in use by the Server.

Code:

#define PORT_CLIENT 1234
#define PORT_SERVER 8888

TArray<int> AUE4_UDP_Socket_Test_Client::UE4_UDP_Socket_IO(FString Message)
{
	FIPv4Endpoint EndPoint_Client (FIPv4Address(127, 0, 0, 1), PORT_CLIENT);
	FIPv4Endpoint EndPoint_Server(FIPv4Address(127, 0, 0, 1), PORT_SERVER);
	
	FSocket *UdpSenderSocket = FUdpSocketBuilder(TEXT("UpdSendSocket"))
		.BoundToEndpoint(EndPoint_Client)
		.AsNonBlocking()
		.AsReusable()
		.WithBroadcast()
		.WithSendBufferSize(2 * 1024 * 1024);
	
	if (UdpSenderSocket)
	{
		UE_LOG(UE4_UDP_Log, Display, TEXT("Send socket create succesful"));

		int32 BytesSent;
		FTimespan waitTime = FTimespan(10);
		TCHAR *serializedChar = Message.GetCharArray().GetData();
		int32 size = FCString::Strlen(serializedChar);
		int32 sent = 0;

		bool success = UdpSenderSocket->SendTo((uint8*)TCHAR_TO_UTF8(serializedChar), size, BytesSent, *EndPoint_Server.ToInternetAddr());
		if (success && BytesSent > 0) // Success
		{
			UE_LOG(UE4_UDP_Log, Display, TEXT("SendTo Successful."));
		}
		else
		{
			UE_LOG(UE4_UDP_Log, Display, TEXT("SendTo Failed"));
		}
	}
}

Hey, did you try this function in iOS? I try this in windows computers and it works fine. But when I launch to Ipad, FUdpSocketBuilder created fail and UdpSenderSocket is NULL. Anyone know why?