Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to coordinate physically seperate servers and clients #26

Open
goarchit opened this issue Feb 19, 2017 · 2 comments
Open

How to coordinate physically seperate servers and clients #26

goarchit opened this issue Feb 19, 2017 · 2 comments

Comments

@goarchit
Copy link

goarchit commented Feb 19, 2017

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.

@goarchit
Copy link
Author

Oddly much further in my development project, and just had this issue come up again. My code seems to be working despite it, which is a bit puzzling.

In this case, its occuring when I make an RPC call to the public IP from the the box that is serving the port.
e.g.:

2017/04/10 21:51:47 gorpc.Server: [66.128.118.34:56796]->[:1958]. Error when reading handshake from client: [EOF]

Where 66.128.118.34 is the public IP address of the machine itself. Will update when I figure this out.

@goarchit
Copy link
Author

goarchit commented Apr 11, 2017

Hmmm, out of ideas. Fortunately the code snippets are fairly short.
Calling code:

37         // Active seed node already found in util.DNSsed() and stored in util.MyDNSServerIP
38
39         c := gorpc.NewTCPClient(util.MyDNSServerIP)
40         c.Start()
41         defer c.Stop()
42
43         d := gorpc.NewDispatcher()
44         d.AddFunc("PeerAdd", func(pi *PeerInfo) string {return PeerAdd(pi)})
45         d.AddFunc("PeerListAll", func() string {return PeerListAll()})
46
47         dc := d.NewFuncClient(c)
48         // Add yourself to your seed node, the seed will tell everyone else
49         _, err := dc.Call("PeerAdd", iAm)
50         if err != nil {
51                 log.Critical("Accounce to seed", util.MyDNSServerIP, "failed:", err)
52         }
53         // Now go ask for all known nodes
54         plstr, err := dc.Call("PeerListAll",nil)
55         if err != nil {
56                 log.Critical("Attempt to get PeerList from seed", util.MyDNSServerIP, "failed:", err)
57         }

Receiving code:

17 var extRPC = gorpc.NewDispatcher()
18 var intCmd *gorpc.Server
19 var extCmd *gorpc.Server
20
21 func Run(c chan bool) {
22
23         // Start common services
24         go server.Wallet(walletCmd)
25         go server.DB(dbCmd)
26
27         // External RPC service first
28         // Start by registering fucntions and types
29         extRPC.AddFunc("Ping", func() string { return "ePong!" })
30         extRPC.AddFunc("PeerAdd", func(pi *PeerInfo) string { return PeerAdd(pi) })
31         extRPC.AddFunc("PeerListAll", func() string { return PeerListAll() })
32
33         // Then launch the server
34         serverIP := ":" + strconv.Itoa(config.Archit.PortBase) // Listen on all interfaces
35         log.Info("Farmer External RPC Server using server address", serverIP)
36         extCmd = gorpc.NewTCPServer(serverIP, extRPC.NewHandlerFunc())
37         err := extCmd.Start()
38         if err != nil {
39                 log.Critical("Farmer External RPC service failed to start: ", err)
40         }
41
42         defer extCmd.Stop()

And the handling function definitions themselves:

43 func PeerAdd(pi *PeerInfo) string {
132 func PeerListAll() string {

Which generate the above error when running, but otherwise appear to be working just fine.

Any suggestions would be greatly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant