示例#1
0
func main() {
	log.SetOutput(os.Stdout)
	flag.Parse()
	if *serverAddr == "" {
		log.Print("--server-addr is required.")
		return
	}

	conn, err := net.Dial("tcp", *serverAddr)
	if err != nil {
		log.Print("Error connecting to server: ", err)
		return
	}
	defer conn.Close()

	artprotodump.DumpServerEvents(conn, nil, log.New(os.Stdout, "debug: ", log.Ldate|log.Ltime), 1024)
}
示例#2
0
文件: parser.go 项目: huin/artemis
func parser(r io.Reader, c io.Closer, l *log.Logger) {
	// On return, discard everything until error.
	defer func() {
		io.Copy(ioutil.Discard, r)
		c.Close()
	}()

	l.Printf("new stream")

	if err := artprotodump.DumpServerEvents(r, nil, l, 1024); err != nil {
		if err == io.EOF {
			l.Printf("end of stream")
		} else {
			l.Printf("error reading frame: %v", err)
		}
	}
}
示例#3
0
文件: main.go 项目: huin/artemis
func main() {
	flag.Parse()
	if *streamFilename == "" {
		log.Fatal("--stream-file is a required argument.")
	}

	var valueIDFn artprotodump.ValueIDFn
	if *valueIDFilename != "" {
		valueIDFile, err := os.Create(*valueIDFilename)
		if err != nil {
			log.Fatal(err)
		}
		defer valueIDFile.Close()
		valueIDFn = func(valueID string, value interface{}) {
			fmt.Fprintf(valueIDFile, "%s\t%T\t%v\n", valueID, value, value)
		}
	}

	l := log.New(os.Stdout, "", 0)
	log.SetOutput(os.Stdout)

	f, err := os.Open(*streamFilename)
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	if *streamIsClient {
		// Debug client stream.
		err = artprotodump.DumpClientEvents(f, l, 1024)
	} else {
		// Debug server stream.
		err = artprotodump.DumpServerEvents(f, valueIDFn, l, 1024)
	}
	if err == io.EOF {
		l.Printf("end of stream")
	} else {
		l.Printf("error reading frame: %v", err)
	}
}
示例#4
0
func readServerConn(r io.Reader, logger *log.Logger) {
	err := artprotodump.DumpServerEvents(r, nil, logger, 1024)
	logger.Print("Error in dumping server data:", err)
}