DTLSServer

    Helper class to implement a DTLS server.

    This class is used to store the state of a DTLS server. Upon it converts connected PacketPeerUDP to accepting them via take_connection as DTLS clients. Under the hood, this class is used to store the DTLS state and cookies of the server. The reason of why the state and cookies are needed is outside of the scope of this documentation.

    1. extends Node
    2. var dtls := PacketPeerDTLS.new()
    3. var connected = false
    4. func _ready():
    5. dtls.connect_to_peer(udp, false) # Use true in production for certificate validation!
    6. func _process(delta):
    7. if dtls.get_status() == PacketPeerDTLS.STATUS_CONNECTED:
    8. if !connected:
    9. # Try to contact server
    10. while dtls.get_available_packet_count() > 0:
    11. print("Connected: %s" % dtls.get_packet().get_string_from_utf8())
    12. connected = true

    Setup the DTLS server to use the given private_key and provide the given certificate to clients. You can pass the optional chain parameter to provide additional CA chain information along with the certificate.


    Note: You must check that the state of the return PacketPeerUDP is , as it is normal that 50% of the new connections will be invalid due to cookie exchange.