> 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/rt-lab/configure-ios/communication-protocol-ios/tcp-and-udp/tcp-udp-loopback-example.md).

# TCP‑UDP Loopback Example

## Description

The **TCP‑UDP Loopback** example can be created by starting a new RT‑LAB project. From the menu bar, select **File > New > RT‑LAB Project**. Enter a name and location for the project, then click **Next**. From the available templates list, navigate to **IO > \_Generic\_ > TCP‑UDP** and select **TCP‑UDP\_loopback**, then click **Finish**.

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-093c155bf334767fd395b058881f087c12ebca66%2FDR-rtlab-tcp-ex1.png?alt=media" alt=""><figcaption></figcaption></figure>

This example demonstrates how to use the TCP‑UDP I/O interface to exchange data over TCP using network interfaces. It illustrates bidirectional data transmission and reception using two TCP streams configured in a loopback setup.

In this example:

* Two TCP streams are instantiated:
  * **Stream 1**: TCP server
  * **Stream 2**: TCP client
* Both streams use a **loopback IP address**.
* Data is exchanged in both directions:
  * Stream 1 TX → Stream 2 RX
  * Stream 2 TX → Stream 1 RX

Although the same signals are exchanged, each stream uses a different default frame format (for example, constants are sent as **U16** on one stream and **U8** on the other).

## Requirements

All necessary prerequisites for this example are covered in the TCP‑UDP **Requirements, Features & Limitations** section.

## Detailed explanation

This example illustrates how to configure and use the TCP‑UDP I/O interface to establish TCP communication between a client and a server within the same system.

### Model preparation and configuration

1. Adjust the TCP‑UDP interface parameters (protocol, port, IP address) if required.
2. Build the model.
3. Load and execute the model.
4. Open **Dashboards**, click **TCPUDP\_dashboard** under **Boards**, then turn ON **S1 Transmit Enable**, **S2 Transmit Enable**, **S1 Receive Enable**, and **S2 Receive Enable**.

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-6a6cf234f11bd3fe706c07f87bdeface4e62bc8f%2FDR-rtlab-tcp-ex2.png?alt=media" alt=""><figcaption></figcaption></figure>

## Simulation and results

Once the model is running and both **Transmit Enable** and **Receive Enable** signals are enabled for each stream:

* The TCP client automatically connects to the TCP server.
* Data exchange begins in both directions.
* Users can modify sine wave frequencies and constant values from the dashboard.
* The received signals and constants are displayed in real time, confirming correct bidirectional communication.

Differences between transmitted and received values may be observed if the selected data types cannot exactly represent the reference values (for example, U8 vs U16).


---

# 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/rt-lab/configure-ios/communication-protocol-ios/tcp-and-udp/tcp-udp-loopback-example.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.
