go-dtls

module
v0.0.0-...-7855ee1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2017 License: MIT

README

Golang: DTLS Protocol

Build Status Coverage Status Go Report Card GoDoc

Work in progress, stay tuned...

Features

  • Client handshake
  • Server handshake
  • Retransmission
  • ...
  • Session Tickets

Installation

go get github.com/pixelbender/go-dtls

DTLS Client

package main

import (
    "github.com/pixelbender/go-dtls/dtls"
    "log"
)

func main() {
    conn, err := dtls.Dial("udp", "example.com:5000", nil)
    if err != nil {
        log.Fatal(err)
    }
    defer conn.Close()
    // Use conn as net.Conn...
}

DTLS Server

package main

import (
    "github.com/pixelbender/go-dtls/dtls"
    "crypto/tls"
    "log"
)

func main() {
    cert, err := tls.LoadX509KeyPair("cert.pem", "key.pem")
    if err != nil {
        log.Fatal(err)
    }
    config := &dtls.Config{Certificates: []tls.Certificate{cert}}
    
    l, err := dtls.Listen("udp", ":5000", config)
    if err != nil {
        log.Fatal(err)
    }
    defer l.Close()
    for {
        // Use l as net.Listener since DTLS is connection-oriented protocol.
        conn, err := l.Accept()
        if err != nil {
            log.Fatal(err)
        }
        go func() {
            defer conn.Close()
            // Serve conn as net.Conn...
        }()
    }
}

Specifications

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL