From 46bde78b11f3f021f2a511df138be9e2fc7506e8 Mon Sep 17 00:00:00 2001 From: John Beisley Date: Wed, 9 Dec 2015 21:46:17 +0000 Subject: [PATCH] Add another example showing getting byte transfer counts on igd2. --- example/example_test.go | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/example/example_test.go b/example/example_test.go index 4cd4219..cb9dd37 100644 --- a/example/example_test.go +++ b/example/example_test.go @@ -7,6 +7,7 @@ import ( "github.com/huin/goupnp" "github.com/huin/goupnp/dcps/internetgateway1" + "github.com/huin/goupnp/dcps/internetgateway2" ) // Use discovered WANPPPConnection1 services to find external IP addresses. @@ -92,8 +93,8 @@ func Example_ReuseDiscoveredDevice() { // Output: } -// Use discovered WANCommonInterfaceConfig1 services to discover byte transfer -// counts. +// Use discovered igd1.WANCommonInterfaceConfig1 services to discover byte +// transfer counts. func Example_WANCommonInterfaceConfig1_GetBytesTransferred() { clients, errors, err := internetgateway1.NewWANCommonInterfaceConfig1Clients() if err != nil { @@ -118,3 +119,30 @@ func Example_WANCommonInterfaceConfig1_GetBytesTransferred() { } // Output: } + +// Use discovered igd2.WANCommonInterfaceConfig1 services to discover byte +// transfer counts. +func Example_WANCommonInterfaceConfig2_GetBytesTransferred() { + clients, errors, err := internetgateway2.NewWANCommonInterfaceConfig1Clients() + if err != nil { + fmt.Fprintln(os.Stderr, "Error discovering service with UPnP:", err) + return + } + fmt.Fprintf(os.Stderr, "Error discovering %d services:\n", len(errors)) + for _, err := range errors { + fmt.Println(" ", err) + } + for _, client := range clients { + if recv, err := client.GetTotalBytesReceived(); err != nil { + fmt.Fprintln(os.Stderr, "Error requesting bytes received:", err) + } else { + fmt.Fprintln(os.Stderr, "Bytes received:", recv) + } + if sent, err := client.GetTotalBytesSent(); err != nil { + fmt.Fprintln(os.Stderr, "Error requesting bytes sent:", err) + } else { + fmt.Fprintln(os.Stderr, "Bytes sent:", sent) + } + } + // Output: +}