-
Notifications
You must be signed in to change notification settings - Fork 98
Description
I'm sure I'm missing something extremely trivial here, but am stuck. I'd like to implement a server on one computer that has a registered service, call it "Ping", that can be called from a client on another server and respond with "Pong".
Per https://godoc.org/github.com/valyala/gorpc#example-Dispatcher--FuncCalls the client wrapper is established as dc := d.NewFuncClient(c).
My concern is that d is not defined in a client only applet.
If I reference the NewTCPClient directly, with a call like c.Call("Ping") the server will error out with:
gorpc.Dispatcher: unsupported request type received from the client: string
Obviously I'm missing something basic, please clue me in.
Server side pseudo code:
d := gorpc.NewDispatcher()
d.AddFunc("Ping", func () string {return "Pong"})
s := gorpc.NewTCPServer("localhost:1234",d.NewHandlerFunc())
s.Start()
Client side pseudo code:
c := gorpc.NewTCPClient("localhost:1234")
c.Start()
c.Call("Ping")
I've also tried:
d := gorpc.NewDispatcher()
c := gorpc.NewTCPClient("localhost:1234")
c.Start()
dc := d.NewFuncClient(c)
resp, err := dc.Call("Ping", nil)
Which results in a " Error when reading handshake from client: [EOF]" error since no d.AddFunc() has been called.
My brain is having problems groking that the client code would need any details beyond a function name that the server handles.
I did find that if I used the 2nd approach and added a d.AddFunc("Ping", func() {}) prior to the dc assignment it works.
Really not clear if that is the right way though or if I just hacked it... Comments please.