12345678910111213141516171819202122232425262728293031323334353637383940 |
- package main
- import (
- "fmt"
- "net"
- "sparrow/pkg/coap"
- )
- const url = "127.0.0.1:56883"
- func main() {
- co, err := net.Dial("udp", url)
- if err != nil {
- fmt.Printf("dial err %s", err.Error())
- }
- token := []byte{
- 0x1,
- 0x2,
- 0x3,
- 0x4,
- 0x5,
- 0x6,
- 0x7,
- 0x8,
- }
- req := &coap.BaseMessage{
- Code: coap.POST,
- Type: coap.CON,
- MessageID: 2,
- //Token: []byte{0, 1, 0x2, 3, 4, 5, 6, 7, 8, 9, 1, 12, 12, 1, 2, 1, 2, 2},
- Token: token,
- Payload: []byte("PAYLOAD"),
- }
- //req.AddOption(coap.URIPath, "/topic/s")
- bytes, err := req.Encode()
- if err != nil {
- fmt.Printf("dial err %s", err.Error())
- }
- co.Write(bytes)
- }
|