TCP vs UDP: How to Choose When Connecting Unreal Engine to External Devices and Apps

ayumaxPluginsObjectDeliverer

TCP vs UDP: How to Choose When Connecting Unreal Engine to External Devices and Apps

Many Unreal Engine projects eventually talk to something outside the engine: a tracking server, a companion app on a tablet, a sensor gateway, a control surface, or a visualization tool built in another framework. One of the first decisions is the transport, and it usually comes down to TCP or UDP.

Which one fits depends less on the protocols themselves than on the data you send.

The short answer

When in doubt, use TCP. Most data that crosses the boundary to another process is data you cannot afford to lose: commands, events, files, state changes that must happen exactly once. TCP delivers every byte in order, and when the link fails, it fails visibly. The connection drops, your code gets a disconnect event, and you can react.

Use UDP when you send a continuous stream of state where each message replaces the previous one, such as object positions or sensor readings. If a few samples never arrive, the next sample corrects the picture. Retransmitting an outdated sample, which is what TCP would do, only delays the newer one that is already waiting.

What the two protocols promise

TCP UDP
Delivery Lost data is retransmitted and arrives Datagrams can be lost, duplicated, or reordered
Order Bytes arrive in the order they were sent Arrival order is not guaranteed
Connection Persistent connection, established with a handshake No connection; send and forget
Message boundaries None: a byte stream, so sends can arrive merged or split Preserved: one datagram is one message
Sending to many receivers One connection per receiver Broadcast to all hosts on the local network

Two rows of this table bite Unreal Engine projects regularly.

The missing message boundaries in TCP mean you have to frame messages yourself. Two consecutive sends can arrive as a single receive, and one large send can arrive in several pieces. A length prefix (a few bytes stating the payload size) or a terminator sequence solves it, but framing has to be part of your message format, and both ends have to agree on it.

With UDP, the frame is the datagram, so boundaries come for free. The constraint is size. A datagram larger than the network’s MTU, typically 1500 bytes on Ethernet, is split into IP fragments, and if any fragment is lost, the entire datagram is discarded. Small payloads such as a pose or a few sensor values are safe; a large JSON snapshot in a single datagram is not.

Five questions that decide it

Must every message arrive?

A message that triggers an action belongs on TCP. “Start recording”, “award the point”, “open the valve”: if it is lost, the receiving side never learns it existed, because UDP reports nothing to either end. The failure surfaces later as behavior that skipped a step, which is an unpleasant bug to chase. TCP retransmits lost data and, when the link itself fails, hands you a disconnect you can handle and log.

Does message order matter?

Suppose an operator presses start, and a moment later presses stop. If the two commands arrive reversed, the receiving logic ends up in the wrong state even though both messages arrived. TCP’s ordering guarantee rules this out. UDP datagrams can overtake one another: rarely on a wired LAN, more often once Wi-Fi or the internet is in the path.

Continuous state is the opposite case. When a prop’s position is sent continuously and two updates arrive swapped, the receiver keeps the newest value and discards the older one, so the reordering costs nothing. Data whose meaning is “this is the current value” tolerates UDP. Data whose meaning is “this happened, and then this happened” needs the ordering guarantee.

Is fresh data more valuable than complete data?

TCP’s guarantees have a price. When a segment is lost, everything behind it waits for the retransmission to arrive before the receiver sees any of it. This is called head-of-line blocking. On a stream of poses or sensor values, the blocked data is already stale by the time it arrives; the receiver would rather have the next sample. Congestion control adds to this on lossy links: after losses, TCP slows its sending rate, which delays the stream further.

UDP has neither behavior. The sender keeps sending, and the receiver keeps the newest datagram. For commands, chat, or file transfer, a brief pause while TCP recovers is harmless; for a state stream, it shows up as motion that stutters.

Does the data have to arrive complete?

Files, saved telemetry, configuration, replay logs: a single gap corrupts the whole result, so completeness is the requirement and TCP is the answer. You can build retransmission and ordering on top of UDP, and some protocols do. At that point you are reimplementing a subset of what TCP already provides, and you inherit the job of testing it.

Do several receivers need the same data?

A tracking server that feeds three Unreal Engine instances and a monitoring tool is a common setup on location and in labs. With UDP broadcast, the sender transmits once and every host on the local network receives it. With TCP, the sender maintains one connection per receiver and repeats the same data for each. Broadcast stays on the local network; once receivers spread across subnets or the internet, each one needs its own connection regardless of protocol.

A quick guide by use case

What you are sending Start with Why
Poses or sensor values, sent continuously UDP The newest sample wins; gaps are corrected by the next sample
State synchronized between two apps UDP Freshness matters more than completeness
Control commands and events TCP Every message matters; loss or reordering breaks behavior
Files, assets, saved data TCP One missing byte corrupts the result
Chat, log lines, notifications TCP Both order and completeness matter
One sender, many receivers on the LAN UDP broadcast One transmission reaches everyone
A web backend or a browser client WebSocket The peer speaks WebSocket, and browsers cannot open raw TCP sockets

Implementing it in Unreal Engine

The engine gives you the raw materials. FSocket, obtained through ISocketSubsystem, covers TCP and UDP at the socket level, with full control and full responsibility: framing, reconnect handling, and the receive loop are yours to write. The IWebSocket interface covers WebSocket clients, and the HTTP module covers request/response calls to REST endpoints.

Two options outside the TCP-or-UDP framing are worth knowing. WebSocket is the practical choice whenever the other end is a web application, because browsers cannot open raw TCP connections. It rides on TCP, so its delivery properties match the TCP column above, with message framing included. Shared memory is worth a look when both processes run on the same PC: the two sides exchange data through a shared memory region without touching the network stack, which suits large messages at high rates. The receiver has to poll for updates, so intermediate writes can be skipped, similar to UDP’s newest-value pattern.

Trying both without rewriting the project

The honest answer to TCP or UDP depends on your data and on the network between the two ends, so the surest way to decide is to run both against the real device. That is only practical if switching does not mean rewriting the communication layer.

ObjectDeliverer, our communication plugin for Unreal Engine, was designed around that switch. It supports TCP/IP, UDP, WebSocket, shared memory (Windows), and file-based communication, and moving between them means replacing the protocol you pass to Start; the send and receive logic stays as it is. Communication runs asynchronously, both C++ and Blueprint can drive it, and the same project runs on Windows, Mac, Linux, iOS, and Android.

The Use Cases guide walks through each protocol with a selection table by goal. If you have questions about a specific setup, please contact us via the Support page.

Follow @AyumaxSoft on X to get the latest updates from AyumaxSoft as soon as they are available.

Related Posts