diff --git a/reporter.go b/reporter.go new file mode 100644 index 0000000..ed8358d --- /dev/null +++ b/reporter.go @@ -0,0 +1 @@ +package iperf diff --git a/tests/client/client.go b/tests/client/client.go index c5ef747..ae3e4a9 100644 --- a/tests/client/client.go +++ b/tests/client/client.go @@ -2,10 +2,8 @@ package main import ( "fmt" - "github.com/BGrewell/go-conversions" "github.com/BGrewell/go-iperf" "os" - "time" ) func main() { @@ -22,8 +20,17 @@ func main() { c.SetOmitSec(omitSec) c.SetProto((iperf.Protocol)(proto)) c.SetLength(length) - - fmt.Printf("blockcount: %s\n", c.BlockCount()) + c.SetJSON(false) + c.SetIncludeServer(false) + c.SetTimeSec(20) + c.SetStreams(2) + reports := c.SetModeLive() + + go func() { + for report := range reports { + fmt.Println(report.String()) + } + }() err := c.Start() if err != nil { @@ -31,20 +38,24 @@ func main() { os.Exit(-1) } - for c.Running { - time.Sleep(100 * time.Millisecond) - } - - if c.Report().Error != "" { - fmt.Println(c.Report().Error) - } else { - for _, entry := range c.Report().End.Streams { - fmt.Println(entry.String()) - } - for _, entry := range c.Report().ServerOutputJson.End.Streams { - fmt.Println(entry.String()) - } - fmt.Printf("DL Rate: %s\n", conversions.IntBitRateToString(int64(c.Report().End.SumReceived.BitsPerSecond))) - fmt.Printf("UL Rate: %s\n", conversions.IntBitRateToString(int64(c.Report().End.SumSent.BitsPerSecond))) - } + // Method 1: Wait for the test to finish by pulling from the 'Done' channel which will block until something is put in or it's closed + <- c.Done + + // Method 2: Poll the c.Running state and wait for it to be 'false' + //for c.Running { + // time.Sleep(100 * time.Millisecond) + //} + + //if c.Report().Error != "" { + // fmt.Println(c.Report().Error) + //} else { + // for _, entry := range c.Report().End.Streams { + // fmt.Println(entry.String()) + // } + // for _, entry := range c.Report().ServerOutputJson.End.Streams { + // fmt.Println(entry.String()) + // } + // fmt.Printf("DL Rate: %s\n", conversions.IntBitRateToString(int64(c.Report().End.SumReceived.BitsPerSecond))) + // fmt.Printf("UL Rate: %s\n", conversions.IntBitRateToString(int64(c.Report().End.SumSent.BitsPerSecond))) + //} }