Remote Procedure Calls with RPC
This lesson covers how Go lets two different machines (a server machine and a client machine) communicate with another using remote calls.
Go programs can communicate with each other through the net/rpc-package
; so this is another application of the client-server paradigm. It provides a convenient means of making function calls over a network connection. Of course, this is only useful when the programs run on different machines. The rpc
package builds on the package gob
to turn its encode/decode automation into transport for method calls across the network.
A server registers an object, making it visible as a service with the type-name of the object. This provides access to the exported methods of that object across a network or other I/O connection for remote clients. It is all about exposing methods on types over a network. The package uses the Http and TCP protocol, and the gob
package for data transport. A server may register multiple objects (services) of different types, but it is an error to register multiple objects of the same type.
Here we discuss a simple example:
Get hands-on with 1400+ tech skills courses.