From cdbe383cea7ffe7a7b7c57ba1926759fb1e32609 Mon Sep 17 00:00:00 2001 From: "Ian M. Jones" Date: Wed, 20 Oct 2021 00:04:23 +0100 Subject: [PATCH] examples: Add client to partner server With the server example running, the client example may be run to connect to its Demo service and call the Foo function. --- _examples/client.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 _examples/client.go diff --git a/_examples/client.go b/_examples/client.go new file mode 100644 index 0000000..da902ff --- /dev/null +++ b/_examples/client.go @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "os" + + "github.com/godbus/dbus/v5" +) + +func main() { + conn, err := dbus.ConnectSessionBus() + if err != nil { + fmt.Fprintln(os.Stderr, "Failed to connect to session bus:", err) + os.Exit(1) + } + defer conn.Close() + + var s string + obj := conn.Object("com.github.guelfey.Demo", "/com/github/guelfey/Demo") + err = obj.Call("com.github.guelfey.Demo.Foo", 0).Store(&s) + if err != nil { + fmt.Fprintln(os.Stderr, "Failed to call Foo function (is the server example running?):", err) + os.Exit(1) + } + + fmt.Println("Result from calling Foo function on com.github.guelfey.Demo interface:") + fmt.Println(s) +}