forked from plgd-dev/go-coap
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
38 lines (34 loc) · 831 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"context"
"fmt"
"log"
"os"
"time"
piondtls "github.com/pion/dtls/v2"
"github.com/matrix-org/go-coap/v2/dtls"
)
func main() {
co, err := dtls.Dial("localhost:5688", &piondtls.Config{
PSK: func(hint []byte) ([]byte, error) {
fmt.Printf("Server's hint: %s \n", hint)
return []byte{0xAB, 0xC1, 0x23}, nil
},
PSKIdentityHint: []byte("Pion DTLS Client"),
CipherSuites: []piondtls.CipherSuiteID{piondtls.TLS_PSK_WITH_AES_128_CCM_8},
})
if err != nil {
log.Fatalf("Error dialing: %v", err)
}
path := "/a"
if len(os.Args) > 1 {
path = os.Args[1]
}
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
resp, err := co.Get(ctx, path)
if err != nil {
log.Fatalf("Error sending request: %v", err)
}
log.Printf("Response payload: %+v", resp)
}