A tiny RPC implemented by Golang
A program requests a service from a program located in another part of address space / another server.
-
Client side
- the client will include the function name and arguments separately
- encode these information
- send to the server side
-
Server side
- retrive the function name and arguments fromt the client side
- use reflect package to call the specified method
- encode the running result of the method, and send back to the client side
// start server
cd example
go run server.go
// start client and make a remote call
cd example
go run client.go
cd /path/to/this/tinyRPC
docker build -t tinyrpc:test .
docker run -p 127.0.0.1:8080:8080 --name rpc -d tinyrpc:test
-
Methods in Golang usually will include the error information in the return values. So in the implementation of the tinyRPC, all methods registered in the server side are required to return the error as the last one in the return list.
Like:
func methodExample(...) (..., error)
-
Test Docker server