> For the complete documentation index, see [llms.txt](https://www.opal-rt.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.opal-rt.com/docs/hypersim/configure-ios/communication-protocol-ios/tcp-and-udp.md).

# TCP & UDP

## Introduction to TCP and UDP

TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) are standard transport‑layer protocols used for Ethernet‑based communication over IP networks. They provide a flexible and widely supported mechanism for exchanging data between simulators, real‑time systems, controllers, and external applications.

TCP and UDP do not define application‑level data models or command semantics. Instead, they provide a generic data transport mechanism, allowing applications to define their own frame formats, data structures, and communication logic. This makes TCP and UDP suitable for a wide range of custom, high‑performance, and real‑time data exchange use cases.

## Protocol characteristics

* **Connection‑oriented vs. connectionless communication**

  **TCP** is connection‑oriented. A connection is established between two endpoints before data transfer begins, ensuring reliable, ordered, and error‑checked delivery.

  **UDP** is connectionless. Data is sent as independent datagrams without establishing a connection, prioritizing low latency and minimal overhead.
* **Peer‑to‑peer architecture**\
  TCP and UDP use a peer‑to‑peer communication model. Either endpoint may send or receive data depending on configuration:
  * In **TCP**, endpoints are typically configured as **client** and **server**.
  * In **UDP**, endpoints exchange datagrams directly without a formal client/server relationship.
* **User‑defined data framing**\
  TCP and UDP transport raw byte streams (TCP) or datagrams (UDP). The structure of the data, such as frames, signals, bit fields, or message boundaries, is entirely defined by the application or simulator configuration.
* **Transport over Ethernet (IP)**\
  Both protocols operate over Ethernet using the TCP/IP stack, supporting standard IP addressing and port‑based communication. They can be deployed on local or routed networks and are fully compatible with standard networking infrastructure and diagnostic tools.
* **Reliability & latency considerations**
  * **TCP** guarantees delivery, preserves packet order, and retransmits lost data, at the cost of additional latency and overhead.
  * **UDP** provides no delivery or ordering guarantees, but offers lower latency and deterministic timing behavior when packet loss is acceptable or managed by the application.
* **Security model (protocol‑agnostic)**\
  TCP and UDP provide no built‑in encryption, authentication, or access control. Secure deployments rely on external mechanisms such as network isolation, firewalls, VPNs, TLS or application‑level security layers.

## How the protocols work

* **Addressing & configuration**\
  Communication endpoints are identified by **IP address** (local and remote) and **Port number** (TCP or UDP).
  * For **TCP**, one endpoint typically listens on a server port. The client initiates the connection.
  * For **UDP**, endpoints send datagrams to a configured remote IP and port. Local ports define where incoming datagrams are received.
* **Data exchange model**\
  **TCP** exchanges a continuous byte stream once the connection is established. Message boundaries must be handled by the application.\
  **UDP** exchanges discrete packets (datagrams), each preserving message boundaries but potentially subject to loss or reordering.
* **Data encoding**\
  Data is transmitted as raw bytes. Applications define data types (booleans, integers, floats, custom bit fields), byte order (endianness), bit ordering, frame layout and alignment. Complex data types may be packed into frames using byte and bit offsets, allowing efficient transmission of structured data.
* **Timing and transmission control**\
  Transmission may occur periodically (e.g., every simulation time step), at a defined decimation rate or conditionally, based on control signals or events. UDP is often preferred for time‑critical streaming, while TCP is preferred when data integrity is critical.

## Example applications

* **Real‑Time Simulation & HIL Systems**\
  Exchanging real‑time signals between a simulator and external controllers, protection relays, or analysis tools.
* **SCADA & Monitoring Systems**\
  Streaming measurements, status values, alarms, and timestamps to supervisory or visualization software.
* **Control & Automation Prototyping**\
  Implementing custom communication interfaces between control algorithms, PLCs, and simulated plants.
* **High‑Performance Data Streaming**\
  Transmitting large vectors of analog values, phasors, or waveform samples with minimal protocol overhead.
* **Inter‑System Integration**\
  Connecting heterogeneous systems that require a flexible, protocol‑agnostic data exchange mechanism without the constraints of standardized fieldbus models.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.opal-rt.com/docs/hypersim/configure-ios/communication-protocol-ios/tcp-and-udp.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
