Unreal Engine TCP/UDP connection with another program

I have looked into the BSD Socket programming and researched the forum but still could not resolve my issue…Here is the thing

Blockquote

void APizzaPizzaCharacter::Connect(){
	FSocket* Socket = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)-CreateSocket(NAME_DGram, TEXT("default"), false);

	FString address = TEXT("127.0.0.1");
	int32 port = 6666;
	FIPv4Address ip;
	FIPv4Address::Parse(address, ip);
	auto addr = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr();
	addr->SetIp(ip.GetValue());//setIP
	addr->SetPort(port);

	if (!Socket->Bind(*addr)){
		if (GEngine){
			GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, "Faied to bind socket");
		}
	}
	else{
		if (GEngine){
			GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, "Socket connect succesuflly");
		}
	}
	Socket->Close();
}

Blockquote

I am running this Connect() in a default myCharacter.cpp. The ISSUE is that, despite the debug message shows socket is connected, the server, which is another program I wrote in C++, did not respond or receive its connection. The server is running on a winsock2. Please help me with that!! I have been working on it for days without progress…Thank you very very much!!

someone help?

You are not sending any data. Datagram (UDP) sockets are not “connected;” they just send data to a given address/port when you tell them to. That address/port will then, hopefully, receive the data, most of the time, assuming it is listening on that address/port and is also a UDP socket, and assuming that a route exists between the sender and the receiver (which, on the same machine, should be true :slight_smile:

#Complete Code Sample For You

I recently posted a completely functional code same for getting UE4 to receive data from a python script via a socket!

Hopefully this code sample can give you better sense of the API and how to work with it

in any case this is a fully functional TCP socket receiver system :slight_smile:

A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums,Receive_Binary_Data_From_an_IP/Port_Into_UE4,(Full_Code_Sample)

Rama

Hi. There is nothing on the link you provided. Could you repost code sample ? Thanks!

rama’s tutorial

Thanks!! I am trying that out!

Thanks! it worked for me! have not yet tried to send from UE4 to other program reversely yet

Dear all,
I’m really new to UE4 and I would need your help. I’m trying to move an object on a scene by receiving it’s desired position and orientation from an external program. Rama’s TCP solution it’s really nice and it seems the way to go. I was able to put the code con a custom Player Controller Class and it compiles fine, but since I’m really a newbie here I don’t know how to proceed further. How can I actually run the code and use the received data to make an object move? I understand that I need something like a Pawn and use it with my custom PlayerController, but how can I link the two things?

Thanks for your help!

Hi marlo3_14, I know this is a bit old, but I’m new to UE4 and am trying to do exactly what you were talking about here (updating a Pawn’s position according to external data stream from another program). I wanted to know if you had succeeded, and what you used if possible. For now, I have managed to have a functional listening server thanks to Rama’s tutorial (with a few modifications since I’m using UE4.18) and I’m about to go to the next steps. Are there any issued that I should be aware of ? Thanks for your help !