package main import ( "fmt" "net" "github.com/hashicorp/go-msgpack/codec" ) type ping struct { SeqNo uint32 Node string SourceAddr []byte SourcePort uint16 SourceNode string } func main() { conn, err := net.Dial("udp", "127.0.0.1:7946") if err != nil { panic(err) } defer conn.Close() p := ping{ SeqNo: 1, Node: "test-node", SourceAddr: []byte{127, 0, 0, 1}, SourcePort: 7947, SourceNode: "ocaml-node", } var buf []byte enc := codec.NewEncoderBytes(&buf, &codec.MsgpackHandle{}) if err := enc.Encode(&p); err != nil { panic(err) } msg := append([]byte{0}, buf...) fmt.Printf("Sending %d bytes: %x\n", len(msg), msg) fmt.Printf("Message type: 0 (ping)\n") fmt.Printf("Msgpack payload: %x\n", buf) n, err := conn.Write(msg) if err != nil { panic(err) } fmt.Printf("Sent %d bytes\n", n) }