December 2017
Intermediate to advanced
316 pages
6h 58m
English
Let us create a simple RPC server that sends the UTC server time back to the RPC client. First, we start with the server.
The RPC server and RPC client should agree upon two things:
The types for the preceding two parameters should exactly match for both server and client:
package mainimport ( "log" "net" "net/http" "net/rpc" "time")type Args struct{}type TimeServer int64func (t *TimeServer) GiveServerTime(args *Args, reply *int64) error { // Fill reply pointer to send the data back *reply = time.Now().Unix() return nil}func main() { // Create a new RPC server timeserver := new(TimeServer) // Register RPC server rpc.Register(timeserver) rpc.HandleHTTP() // Listen for requests on port ...Read now
Unlock full access