UDP connection returning false

Hi, I set up a UDP-Server through node.js and I’m trying to connect to it using this function;

bool UGameServer::ConnectToServer(int32 port)
{

	Socket = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateSocket(NAME_DGram, TEXT("default"), true);
	FString address = TEXT("127.0.0.1");

	TSharedRef < FInternetAddr > addr = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr();
	FIPv4Address ip;
	FIPv4Address::Parse(address, ip);

	addr->SetIp(ip.GetValue());
	addr->SetPort(port);
	if (bool connected = Socket->Connect(*addr))
	{
		return true;
	}
	else
	{
		return false;
	}
}

However it returns false every time.
http://i.imgur.com/qpIArhH.png - This is what my blueprint looks like too. Not sure what could be wrong. Any ideas?

Hi Netzone,

The UE4 socket interface follows the traditional BSD socket interface pretty closely, so it may be helpful to familiarize yourself with it as well.

The Connect function is used to initiate a connection on a connection-based protocol, like TCP. But UDP is connectionless, so in order to communicate with a UDP server, you’ll need to bind the socket to an address (your local address is fine, you can use ISocketSubsystem::GetLocalBindAddr) with ISocketSubsystem::BindNextPort or FSocket::Bind. You should then be able to send and receive data with FSocket::SendTo and FSocket::RecvFrom.

Also, the FUdpSocketBuilder helper class might be of some use. It simplifies the process of creating a UDP socket. For example:

Socket = FUdpSocketBuilder(TEXT("MySocket"))
    .AsNonBlocking()
    .AsReusable()
    .BoundToAddress(ip)
    .BoundToPort(port);