Skip to content

Instantly share code, notes, and snippets.

@roxtar
Created February 18, 2016 16:45
Show Gist options
  • Save roxtar/ab4b5ffdc6cae2b80652 to your computer and use it in GitHub Desktop.
Save roxtar/ab4b5ffdc6cae2b80652 to your computer and use it in GitHub Desktop.
Simple application to test the Metron Doppler TCP link
package main
import (
"encoding/binary"
"fmt"
"net"
"os"
"github.com/cloudfoundry/sonde-go/events"
"github.com/gogo/protobuf/proto"
)
func main() {
address := os.Args[1]
conn, err := net.Dial("tcp", address)
if err != nil {
panic(err)
}
message := &events.Envelope{
EventType: events.Envelope_CounterEvent.Enum(),
Timestamp: proto.Int64(12355),
Origin: proto.String("testapp"),
CounterEvent: &events.CounterEvent{
Name: proto.String("testapp_counter"),
Delta: proto.Uint64(123),
Total: proto.Uint64(1235455),
},
}
bytes, err := proto.Marshal(message)
if err != nil {
panic(err)
}
var n uint32
n = uint32(len(bytes))
err = binary.Write(conn, binary.LittleEndian, n)
if err != nil {
panic(err)
}
_, err = conn.Write(bytes)
if err != nil {
panic(err)
}
fmt.Printf("Message written successfully!\n")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment