# Enable DTLS encryption

> Configure your Relay client to use Datagram Transport Layer Security for encrypted connections.

> **Note:**
>
> Enabling DTLS encryption only enables encryption of message. Other Relay behavior, such as [timeouts](/relay/client-timeouts.md.md), remains the same.

Relay supports [DTLS encryption](./dtls-encryption.md) of all UDP communication to and from the [Relay servers](./relay-servers.md). Set the Relay server `RelayProtocol` to `DTLS` when creating an allocation as a host player to enable DTLS encryption.

> **Note:**
>
> Players joining the host player can use a different connection type than the host player. However, most gaming platforms required encrypted connections.

The following code snippet shows how to create sessions with DTLS encryption:

```cs
using Unity.Services.Multiplayer;

// As host: create a session with DTLS encryption explicitly set
var session = await MultiplayerService.Instance.CreateSessionAsync(
    new SessionOptions { MaxPlayers = 4 }
        .WithRelayNetwork()
        .WithNetworkOptions(new NetworkOptions { RelayProtocol = RelayProtocol.DTLS }));

Debug.Log($"Session created with join code: {session.Code}");
```

The following code snippet shows how to join a session with DTLS encryption:

```cs
// As client: join by code with DTLS
var session = await MultiplayerService.Instance.JoinSessionByCodeAsync(
    joinCode,
    new JoinSessionOptions()
        .WithNetworkOptions(new NetworkOptions { RelayProtocol = RelayProtocol.DTLS }));
```
