# \[New Wiki\] UDP Sockets, Sending / Receiving any custom data from 1 UE4 instance to another

**URL:** <https://forums.unrealengine.com/t/new-wiki-udp-sockets-sending-receiving-any-custom-data-from-1-ue4-instance-to-another/57491>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [March 7, 2016, 5:50am UTC](https://forums.unrealengine.com/t/new-wiki-udp-sockets-sending-receiving-any-custom-data-from-1-ue4-instance-to-another/57491 "2016-03-07T05:50:47Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [March 7, 2016, 5:50am UTC](https://forums.unrealengine.com/t/new-wiki-udp-sockets-sending-receiving-any-custom-data-from-1-ue4-instance-to-another/57491/1 "2016-03-07T05:50:47Z")

</div>

Dear Community,

I’ve justed posted a new wiki that shows you how you can send/receive any custom data you want from 1 UE4 instance to another, anywhere in the world using UDP connection!

**Wiki Link**

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

 ![UDPVictory.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/9/c/9c4be0afc37c3ff2b34d5606233b4b24d5ecc88a.jpeg)

![465c97e71f555224eab45a2f098c46ae669ed85a.jpeg](https://d1ap1mz92jnks1.cloudfront.net/images/transparent.png)

---

<div class="post-metadata">

**Author:** ![msvcrt](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@msvcrt](https://forums.unrealengine.com/u/msvcrt)\
**Post date:** [March 8, 2016, 12:21am UTC](https://forums.unrealengine.com/t/new-wiki-udp-sockets-sending-receiving-any-custom-data-from-1-ue4-instance-to-another/57491/2 "2016-03-08T00:21:05Z")

</div>

Thanks for sharing this, Rama! 🙂

---

<div class="post-metadata">

**Author:** ![Scienziatogm](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/scienziatogm/32/906600_2.png) [@Scienziatogm](https://forums.unrealengine.com/u/Scienziatogm)\
**Post date:** [March 8, 2016, 11:22pm UTC](https://forums.unrealengine.com/t/new-wiki-udp-sockets-sending-receiving-any-custom-data-from-1-ue4-instance-to-another/57491/3 "2016-03-08T23:22:11Z")

</div>

Thanks for sharing this. Good job!

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [March 14, 2016, 4:43am UTC](https://forums.unrealengine.com/t/new-wiki-udp-sockets-sending-receiving-any-custom-data-from-1-ue4-instance-to-another/57491/4 "2016-03-14T04:43:36Z")

</div>

Very nice to hear from you both!

I hope everyone enjoys my wiki!

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

❤

Rama

---

<div class="post-metadata">

**Author:** ![ArdentDrako](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ardentdrako/32/88706_2.png) [@ArdentDrako](https://forums.unrealengine.com/u/ArdentDrako)\
**Post date:** [March 14, 2016, 10:01am UTC](https://forums.unrealengine.com/t/new-wiki-udp-sockets-sending-receiving-any-custom-data-from-1-ue4-instance-to-another/57491/5 "2016-03-14T10:01:29Z")

</div>

rama, first you teach pointers, then you pull this! its like you can tell what i have been working on then you show me how!

thanks for this

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [March 22, 2016, 3:42am UTC](https://forums.unrealengine.com/t/new-wiki-udp-sockets-sending-receiving-any-custom-data-from-1-ue4-instance-to-another/57491/6 "2016-03-22T03:42:04Z")

</div>

> [@CNKIT;492782](#):
>
> rama, first you teach pointers, then you pull this! its like you can tell what i have been working on then you show me how!
> 
> thanks for this

Hee hee!

I am happy to have helped!

🙂

Rama

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_71046e02](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_71046e02](https://forums.unrealengine.com/u/anonymous_user_71046e02)\
**Post date:** [August 17, 2016, 2:28am UTC](https://forums.unrealengine.com/t/new-wiki-udp-sockets-sending-receiving-any-custom-data-from-1-ue4-instance-to-another/57491/7 "2016-08-17T02:28:55Z")

</div>

Hi Rama,I did as you said in the wiki tutorial,but I can’t get it work.  
The sender worked OK but the receiver can not receive any data.  
It seems that the recv function did not work.  
 ![GRW86N_A.png](https://d3kjluh73b9h9o.cloudfront.net/original/3X/2/9/29c30bc08aab8c79c4e9cbbfd5ed307f32050c90.png)

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [August 19, 2016, 3:50pm UTC](https://forums.unrealengine.com/t/new-wiki-udp-sockets-sending-receiving-any-custom-data-from-1-ue4-instance-to-another/57491/8 "2016-08-19T15:50:59Z")

</div>

Well I shared with you the code that I myself used, so you might want to verify your external program and UE4, it most be some kind of connection issue that I cannot assist with 🙂

Rama

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_aa38068d](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_aa38068d](https://forums.unrealengine.com/u/anonymous_user_aa38068d)\
**Post date:** [October 22, 2016, 8:01pm UTC](https://forums.unrealengine.com/t/new-wiki-udp-sockets-sending-receiving-any-custom-data-from-1-ue4-instance-to-another/57491/9 "2016-10-22T20:01:08Z")

</div>

Ive got a big problem.

Your code is working great, unfortunately i can’t get it working to spawn an actor after UDP event.  
My Engine always crashes because the UDP receiving is not inside main thread.  
BP Event is being called, but when i try to Spawn an Actor, whether in a custom character function that is called by RamaUDPReceiver.cpp or inside the called blueprint BPEvent\_DataReceived.

How can i go back to the main thread that i can work as usual ? this kills me ☹

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_87b7f658](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_87b7f658](https://forums.unrealengine.com/u/anonymous_user_87b7f658)\
**Post date:** [November 9, 2016, 6:33am UTC](https://forums.unrealengine.com/t/new-wiki-udp-sockets-sending-receiving-any-custom-data-from-1-ue4-instance-to-another/57491/10 "2016-11-09T06:33:18Z")

</div>

> [@mayaping;582142](#):
>
> Hi Rama,I did as you said in the wiki tutorial,but I can’t get it work.  
> The sender worked OK but the receiver can not receive any data.  
> It seems that the recv function did not work.  
> ![GRW86N_A.png](https://d3kjluh73b9h9o.cloudfront.net/original/3X/2/9/29c30bc08aab8c79c4e9cbbfd5ed307f32050c90.png)

Same problem here. Have you solved it?

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [November 9, 2016, 11:49pm UTC](https://forums.unrealengine.com/t/new-wiki-udp-sockets-sending-receiving-any-custom-data-from-1-ue4-instance-to-another/57491/11 "2016-11-09T23:49:49Z")

</div>

> [@sascha1337;613286](#):
>
> Ive got a big problem.
> 
> Your code is working great, unfortunately i can’t get it working to spawn an actor after UDP event.  
> My Engine always crashes because the UDP receiving is not inside main thread.  
> BP Event is being called, but when i try to Spawn an Actor, whether in a custom character function that is called by RamaUDPReceiver.cpp or inside the called blueprint BPEvent\_DataReceived.
> 
> How can i go back to the main thread that i can work as usual ? this kills me ☹

> [@vito\_BumpingWorkshop;620954](#):
>
> Same problem here. Have you solved it?

What you can do is a run a 0.01 timer in the game thread that watches for a global bool flag that you can set inside of the Recv func, and same raw data as well like location or type of actor to spawn (FVector, String, float, etc).

As long as you dont use pointers, you can set that simple data from ::Recv, and set the bool that you want the timer in the game thread to look for and know that the other data has now been filled.

When using simple data types only, this sort of communication between game thread and the UDP socket thread will go quite well 🙂

If your updates are happening ultra frequently, faster than 0.01 you might have issues but even something like every 0.1 seconds should give the game thread enough time to get the updates.

The game thread should set the bool back to false once it acts on the data so it knows not to run again till the other thread flips the bool again.

Rama

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_87b7f658](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_87b7f658](https://forums.unrealengine.com/u/anonymous_user_87b7f658)\
**Post date:** [November 10, 2016, 6:14am UTC](https://forums.unrealengine.com/t/new-wiki-udp-sockets-sending-receiving-any-custom-data-from-1-ue4-instance-to-another/57491/12 "2016-11-10T06:14:28Z")

</div>

> [@Rama;621345](#):
>
> What you can do is a run a 0.01 timer in the game thread that watches for a global bool flag that you can set inside of the Recv func, and same raw data as well like location or type of actor to spawn (FVector, String, float, etc).
> 
> As long as you dont use pointers, you can set that simple data from ::Recv, and set the bool that you want the timer in the game thread to look for and know that the other data has now been filled.
> 
> When using simple data types only, this sort of communication between game thread and the UDP socket thread will go quite well 🙂
> 
> If your updates are happening ultra frequently, faster than 0.01 you might have issues but even something like every 0.1 seconds should give the game thread enough time to get the updates.
> 
> The game thread should set the bool back to false once it acts on the data so it knows not to run again till the other thread flips the bool again.
> 
> Rama

Thanks for helping. I found a solution in another guy’s post though.

According to him, it’s a thing after 4.12.5. All that’s needed is to call Start() on FUdpSocketReceiver.

Anyway this solved my problem.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_df6c2680](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_df6c2680](https://forums.unrealengine.com/u/anonymous_user_df6c2680)\
**Post date:** [November 10, 2016, 8:07pm UTC](https://forums.unrealengine.com/t/new-wiki-udp-sockets-sending-receiving-any-custom-data-from-1-ue4-instance-to-another/57491/13 "2016-11-10T20:07:21Z")

</div>

Hi Rama

I can’t get it work.

got Compiler errors… pls help.

RamaUDPReceiver.h(14): error C2079: “RamaUDPReceiver\_eventBPEvent\_DataReceived\_Parms::ReceivedData” verwendet undefiniertes struct “FAnyCustomData”  
UDPSendReceive.generated.cpp(16): error C2440: “=”: “const FAnyCustomData” kann nicht in “int” konvertiert werden  
UDPSendReceive.generated.cpp(16): note: Kein benutzerdefinierter Konvertierungsoperator verfügbar, der diese Konvertierung durchführen kann, oder der Operator kann nicht aufgerufen werden  
RamaUDPReceiver.h(14): error C2079: “RamaUDPReceiver\_eventBPEvent\_DataReceived\_Parms::ReceivedData” verwendet undefiniertes struct “FAnyCustomData”  
RamaUDPReceiver.cpp(76): error C2079: “Data” verwendet undefiniertes struct “FAnyCustomData”  
RamaUDPReceiver.cpp(80): error C2664: “void ARamaUDPReceiver::BPEvent\_DataReceived(const FAnyCustomData &)” : Konvertierung von Argument 1 von “int” in “const FAnyCustomData &” nicht möglich  
RamaUDPReceiver.cpp(80): note: Ursache: Konvertierung von “int” in “const FAnyCustomData” nicht möglich  
RamaUDPReceiver.cpp(80): note: Der nicht definierte Typ “FAnyCustomData” wird verwendet.  
RamaUDPReceiver.generated.h(11): note: Siehe Deklaration von “FAnyCustomData”  
RamaUDPSender.cpp(35): error C2511: “bool ARamaUDPSender::StartUDPSender(const FString &,const FString &,const int32)”: Überladene Memberfunktion nicht in “ARamaUDPSender” gefunden  
RamaUDPSender.h(15): note: Siehe Deklaration von “ARamaUDPSender”  
RamaUDPSender.cpp(37): error C2597: Ungültiger Verweis auf nicht-statischen Member “ARamaUDPSender::RemoteAddr”  
RamaUDPSender.cpp(40): error C2227: Links von “-\>SetIp” muss sich ein Zeiger auf Klassen-/Struktur-/Union-/generischen Typ befinden.  
RamaUDPSender.cpp(41): error C2227: Links von “-\>SetPort” muss sich ein Zeiger auf Klassen-/Struktur-/Union-/generischen Typ befinden.  
RamaUDPSender.cpp(45): error C2352: “ARamaUDPSender::ScreenMsg”: Unzulässiger Aufruf einer nicht statischen Memberfunktion  
RamaUDPSender.h(51): note: Siehe Deklaration von “ARamaUDPSender::ScreenMsg”  
RamaUDPSender.cpp(52): error C2597: Ungültiger Verweis auf nicht-statischen Member “ARamaUDPSender::SenderSocket”  
RamaUDPSender.cpp(59): error C2227: Links von “-\>SetSendBufferSize” muss sich ein Zeiger auf Klassen-/Struktur-/Union-/generischen Typ befinden.  
RamaUDPSender.cpp(60): error C2227: Links von “-\>SetReceiveBufferSize” muss sich ein Zeiger auf Klassen-/Struktur-/Union-/generischen Typ befinden.  
RamaUDPSender.cpp(80): error C2079: “NewData” verwendet undefiniertes struct “FAnyCustomData”  
RamaUDPSender.cpp(81): error C2228: Links von “.Scale” müssen sich in einer Klasse/Struktur/Union befinden  
RamaUDPSender.cpp(81): note: Typ ist “int”  
RamaUDPSender.cpp(82): error C2228: Links von “.Count” müssen sich in einer Klasse/Struktur/Union befinden  
RamaUDPSender.cpp(82): note: Typ ist “int”  
RamaUDPSender.cpp(83): error C2228: Links von “.Color” müssen sich in einer Klasse/Struktur/Union befinden  
RamaUDPSender.cpp(83): note: Typ ist “int”

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_87b7f658](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_87b7f658](https://forums.unrealengine.com/u/anonymous_user_87b7f658)\
**Post date:** [November 11, 2016, 3:59am UTC](https://forums.unrealengine.com/t/new-wiki-udp-sockets-sending-receiving-any-custom-data-from-1-ue4-instance-to-another/57491/14 "2016-11-11T03:59:33Z")

</div>

> [@jwinns;621721](#):
>
> Hi Rama
> 
> I can’t get it work.
> 
> got Compiler errors… pls help.
> 
> RamaUDPReceiver.h(14): error C2079: “RamaUDPReceiver\_eventBPEvent\_DataReceived\_Parms::ReceivedData” verwendet undefiniertes struct “FAnyCustomData”  
> UDPSendReceive.generated.cpp(16): error C2440: “=”: “const FAnyCustomData” kann nicht in “int” konvertiert werden  
> UDPSendReceive.generated.cpp(16): note: Kein benutzerdefinierter Konvertierungsoperator verfügbar, der diese Konvertierung durchführen kann, oder der Operator kann nicht aufgerufen werden  
> RamaUDPReceiver.h(14): error C2079: “RamaUDPReceiver\_eventBPEvent\_DataReceived\_Parms::ReceivedData” verwendet undefiniertes struct “FAnyCustomData”  
> RamaUDPReceiver.cpp(76): error C2079: “Data” verwendet undefiniertes struct “FAnyCustomData”  
> RamaUDPReceiver.cpp(80): error C2664: “void ARamaUDPReceiver::BPEvent\_DataReceived(const FAnyCustomData &)” : Konvertierung von Argument 1 von “int” in “const FAnyCustomData &” nicht möglich  
> RamaUDPReceiver.cpp(80): note: Ursache: Konvertierung von “int” in “const FAnyCustomData” nicht möglich  
> RamaUDPReceiver.cpp(80): note: Der nicht definierte Typ “FAnyCustomData” wird verwendet.  
> RamaUDPReceiver.generated.h(11): note: Siehe Deklaration von “FAnyCustomData”  
> RamaUDPSender.cpp(35): error C2511: “bool ARamaUDPSender::StartUDPSender(const FString &,const FString &,const int32)”: Überladene Memberfunktion nicht in “ARamaUDPSender” gefunden  
> RamaUDPSender.h(15): note: Siehe Deklaration von “ARamaUDPSender”  
> RamaUDPSender.cpp(37): error C2597: Ungültiger Verweis auf nicht-statischen Member “ARamaUDPSender::RemoteAddr”  
> RamaUDPSender.cpp(40): error C2227: Links von “-\>SetIp” muss sich ein Zeiger auf Klassen-/Struktur-/Union-/generischen Typ befinden.  
> RamaUDPSender.cpp(41): error C2227: Links von “-\>SetPort” muss sich ein Zeiger auf Klassen-/Struktur-/Union-/generischen Typ befinden.  
> RamaUDPSender.cpp(45): error C2352: “ARamaUDPSender::ScreenMsg”: Unzulässiger Aufruf einer nicht statischen Memberfunktion  
> RamaUDPSender.h(51): note: Siehe Deklaration von “ARamaUDPSender::ScreenMsg”  
> RamaUDPSender.cpp(52): error C2597: Ungültiger Verweis auf nicht-statischen Member “ARamaUDPSender::SenderSocket”  
> RamaUDPSender.cpp(59): error C2227: Links von “-\>SetSendBufferSize” muss sich ein Zeiger auf Klassen-/Struktur-/Union-/generischen Typ befinden.  
> RamaUDPSender.cpp(60): error C2227: Links von “-\>SetReceiveBufferSize” muss sich ein Zeiger auf Klassen-/Struktur-/Union-/generischen Typ befinden.  
> RamaUDPSender.cpp(80): error C2079: “NewData” verwendet undefiniertes struct “FAnyCustomData”  
> RamaUDPSender.cpp(81): error C2228: Links von “.Scale” müssen sich in einer Klasse/Struktur/Union befinden  
> RamaUDPSender.cpp(81): note: Typ ist “int”  
> RamaUDPSender.cpp(82): error C2228: Links von “.Count” müssen sich in einer Klasse/Struktur/Union befinden  
> RamaUDPSender.cpp(82): note: Typ ist “int”  
> RamaUDPSender.cpp(83): error C2228: Links von “.Color” müssen sich in einer Klasse/Struktur/Union befinden  
> RamaUDPSender.cpp(83): note: Typ ist “int”

It seems your custom struct wasn’t declared properly? Those UXXX macros can be tricky since they seem to be implemented in the generated headers. I’d suggest you declare that in an engine generated unreal class. Z.B. you add a new c++ class in engine that inherits from Actor and you cut and paste everything from USTRUCT() to the FORCEINLINE function to the new class’s header, right above the UCLASS() and beneath the #include “…generated.h”

Also make sure your “bool ARamaUDPSender::StartUDPSender(const FString &,const FString &,const int32)” function has consistent parameters in your header and source file.

In general, with those mostly helpful .generated.h, you’ll likely get a ton of errors for even a tiny typo. Just debug from the first error you get and compile after you(think you)'ve done something right.
