Documentation

Support

Relay

Relay

Enable DTLS encryption

Configure your Relay client to use Datagram Transport Layer Security for encrypted connections.
Read time 1 minuteLast updated a month ago

Relay supports DTLS encryption of all UDP communication to and from the Relay servers. Set the Relay server
connectionType
to
dtls
when creating an allocation as a host player to enable DTLS encryption.
The following code snippet has a function,
AllocateRelayServerAndGetJoinCode
, that shows how to use the Relay SDK to create an allocation, request a join code, and configure the connection type as DTLS.
public static async Task<(string ipv4address, ushort port, byte[] allocationIdBytes, byte[] connectionData, byte[] key, string joinCode)> AllocateRelayServerAndGetJoinCode(int maxConnections, string region = null){ Allocation allocation; string createJoinCode; try { allocation = await RelayService.Instance.CreateAllocationAsync(maxConnections, region); } catch (Exception e) { Debug.LogError($"Relay create allocation request failed {e.Message}"); throw; } Debug.Log($"server connection data: {allocation.ConnectionData[0]} {allocation.ConnectionData[1]}"); Debug.Log($"server allocation ID: {allocation.AllocationId}"); try { createJoinCode = await RelayService.Instance.GetJoinCodeAsync(allocation.AllocationId); } catch { Debug.LogError("Relay create join code request failed"); throw; } var dtlsEndpoint = allocation.ServerEndpoints.First(e => e.ConnectionType == "dtls"); return (dtlsEndpoint.Host, (ushort)dtlsEndpoint.Port, allocation.AllocationIdBytes, allocation.ConnectionData, allocation.Key, createJoinCode);}

Enable DTLS encryption • Relay • Unity Docs