# TCP and UDP services

Source: https://openpanel.sh/docs/tcp-udp

Public TCP and UDP ports on OpenPanel's edge for services that are not websites, such as databases, game servers and brokers.

A public service's `http` ports are reached through its domains. Its `tcp` and `udp` ports are reached differently: each one gets its own public port on OpenPanel's edge, and the edge carries the traffic to the service through the connection your server's agent keeps to OpenPanel. Your server opens no port for it.

In the console, ports are set in the **Networking** card of a service's **Settings** tab, and in the **Networking** section of **New service**. The [CLI](/docs/cli), the [API](/docs/api) and [MCP](/docs/ai) do the same.

## Give a service a public port [#give-a-service-a-public-port]

Make the service public and list the port with its protocol:

<Tabs items={["Console","CLI","API"]}>
<Tab value="Console">
Open the project, click the service on the canvas, and go to its **Settings** tab. In **Networking**, choose **Public** under **Reach**, add the port with its **Protocol** (TCP or UDP) and **Port**, and click **Save**. Once saved, the service's **Overview** tab lists the address the edge gave it under **Addresses**, such as `edge.openpanel.sh:30001`.
</Tab>

<Tab value="CLI">
```sh
openpanel services create game --project shop \
  --image itzg/minecraft-server --port tcp:25565 --public --server my-server
openpanel services get game --project shop
```

The second command shows the port the edge gave it, such as `tcp:25565 (edge :30001)`.
</Tab>

<Tab value="API">
```sh
curl -X PATCH https://openpanel.sh/api/v1/services/$SERVICE_ID \
  -H "Authorization: Bearer $OPENPANEL_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"exposure": "public", "ports": [{"protocol": "tcp", "port": 25565}]}'
```

Each `tcp` or `udp` port in the answer carries its `edgePort`.
</Tab>
</Tabs>

Then [deploy](/docs/deploy) the service. Clients connect to the edge, `edge.openpanel.sh`, on the edge port:

```sh
nc -vz edge.openpanel.sh 30001
```

<Callout type="warn" title="The edge's name is not in DNS yet">
`edge.openpanel.sh` does not resolve yet, so clients cannot reach a public TCP or UDP port by that name today. This page changes when it does.
</Callout>

## The edge port [#the-edge-port]

| | |
|---|---|
| Range | 30000 to 32767 |
| Chosen by | OpenPanel, the first free one when the port is saved |
| Unique | Per transport: a TCP port and a UDP port can share a number |
| Kept | As long as the service stays public and keeps that port, across deploys and other changes |
| Released | When the port is removed or the service stops being public; another service can get it later |

You cannot choose the edge port yourself.

## How traffic flows [#how-traffic-flows]

- **TCP:** each connection goes to a ready replica, the one with the fewest connections in flight. Bytes pass through as they are: the edge adds no TLS, so a protocol that needs encryption uses its own, as PostgreSQL and MySQL do.
- **UDP:** the datagrams of one client address go to one replica. That flow ends after 60 seconds without a datagram either way, and a port carries at most 4,096 flows at once.
- The service sees connections come from the OpenPanel agent on its server, not from the client: the client's address is not passed on for TCP and UDP.
- The edge listens on a port only while a connected server is set to run the service. When all its servers are offline, connections are refused at once rather than left hanging.

## On a private service, or one with no address [#on-a-private-service-or-one-with-no-address]

Only a public service's TCP and UDP ports reach the edge. On a private service each port gets a port on its server's `127.0.0.1` instead; see [Private addresses](/docs/network/private-addresses). A service with no address is reached only by the project's other services on the same server, by its name.

<Cards>
<Card href="/docs/tcp-udp/ports" title="Ports reference" description="Every port OpenPanel uses on your servers." />

<Card href="/docs/projects/settings#ports" title="Ports setting" description="How the list of ports works." />
</Cards>