this repo has no description
at main 858 B view raw
1package main 2 3import ( 4 "fmt" 5 "net" 6 7 "github.com/hashicorp/go-msgpack/codec" 8) 9 10type ping struct { 11 SeqNo uint32 12 Node string 13 SourceAddr []byte 14 SourcePort uint16 15 SourceNode string 16} 17 18func main() { 19 conn, err := net.Dial("udp", "127.0.0.1:7946") 20 if err != nil { 21 panic(err) 22 } 23 defer conn.Close() 24 25 p := ping{ 26 SeqNo: 1, 27 Node: "test-node", 28 SourceAddr: []byte{127, 0, 0, 1}, 29 SourcePort: 7947, 30 SourceNode: "ocaml-node", 31 } 32 33 var buf []byte 34 enc := codec.NewEncoderBytes(&buf, &codec.MsgpackHandle{}) 35 if err := enc.Encode(&p); err != nil { 36 panic(err) 37 } 38 39 msg := append([]byte{0}, buf...) 40 fmt.Printf("Sending %d bytes: %x\n", len(msg), msg) 41 fmt.Printf("Message type: 0 (ping)\n") 42 fmt.Printf("Msgpack payload: %x\n", buf) 43 44 n, err := conn.Write(msg) 45 if err != nil { 46 panic(err) 47 } 48 fmt.Printf("Sent %d bytes\n", n) 49}