DTLS over UDP on Server and Client Components

From sgcWebSockets 2022.8.0 DTLS over UDP is supported by Server and Client UDP components. This means that now you can send encrypted messages using UDP (like WebSocket or HTTP protocol that work over TLS).

From Wikipedia: Datagram Transport Layer Security (DTLS) is a communications protocol providing security to datagram-based applications by allowing them to communicate in a way designed[1][2] to prevent eavesdropping, tampering, or message forgery. The DTLS protocol is based on the stream-oriented Transport Layer Security (TLS) protocol and is intended to provide similar security guarantees.


The configuration is very similar to other components. There is a new property called DTLSOptions where you can configure the DTLS options like file certificate, private key, certificate verification... To enabled DTLS just set the DTLS property to True before the server starts or before send a message from a client to server.

The certificate must be in PEM format, so if the certificate has a different format, first convert to PEM.

DTLS requires openSSL 1.1+ so the default Indy version that comes with  Rad Studio currently doesn't support it. Only sgcWebSockets Enterprise version supports DTLS (because this version comes with a custom indy version that supports openSSL 1.1 and 3.0).


  // ... server
  server := TsgcUDPServer.Create(nil);
  server.Port := StrToInt(txtDefaultPort.Text);
  With server.Bindings.Add do
    IP := '';
    Port := 5430;
  // ... dtls
  server.DTLS := True;
  server.DTLSOptions.CertFile := 'certificate.pem';
  server.DTLSOptions.KeyFile := 'privatekey.pem';
  // ... active
  server.Active := True; 


    // ... client
    client.Host := '';
    client.Port := 5430;

    client.DTLS := True;
    client.DTLSOptions.CertFile := 'certificate.pem';
    client.DTLSOptions.KeyFile := 'privatekey.pem';

    client.WriteData('Hello from sgcWebSockets!!!'); 


Find below a link to a DTLS over UDP demo that shows how it works on windows using the sgcWebSockets library.

File Name: udp_dtls
File Size: 4.4 mb
Download File
Stay Informed

When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.

RTCPeerConnection P2P
Delphi 11.2 iOS ARM Simulator

Related Posts