PracticeDev/study_go/test_iperf/client.go

35 lines
490 B
Go
Raw Normal View History

2022-12-20 17:31:11 +08:00
package main
import (
"fmt"
"github.com/BGrewell/go-iperf"
"os"
)
func main() {
c := iperf.NewClient("127.0.0.1")
c.SetJSON(true)
c.SetIncludeServer(true)
c.SetStreams(4)
c.SetTimeSec(3)
c.SetInterval(1)
liveReports := c.SetModeLive()
go func() {
for report := range liveReports {
fmt.Println(report.String())
}
}()
err := c.Start()
if err != nil {
fmt.Printf("failed to start client: %v\n", err)
os.Exit(-1)
}
<-c.Done
fmt.Println(c.Report().String())
}