Enable DTLS encryption
Configure your Relay client to use Datagram Transport Layer Security for encrypted connections.
Read time 1 minuteLast updated 14 hours ago
Relay supports DTLS encryption of all UDP communication to and from the Relay servers. Set the Relay server
connectionTypedtls
The following code snippet has a function,
AllocateRelayServerAndGetJoinCodepublic 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);}