Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RemoteCaller ¶
type RemoteCaller struct {
// contains filtered or unexported fields
}
RemoteCaller represents a client that makes remote procedure calls (RPC).
Fields:
- port: The port number of the server to connect to.
func NewRemoteCaller ¶
func NewRemoteCaller(port int) *RemoteCaller
NewRemoteCaller creates a new instance of RemoteCaller.
Parameters:
- port: The port number of the server to connect to.
Returns:
- A pointer to a new RemoteCaller instance.
func (*RemoteCaller) Call ¶
func (r *RemoteCaller) Call(methodName string, args any, reply any) error
Call invokes a remote method on the server.
Parameters:
- methodName: The name of the method to call on the server.
- args: The arguments to pass to the remote method.
- reply: A pointer to the variable where the method's response will be stored.
Returns:
- An error if the call fails or the server is unreachable.
Example:
caller := NewRemoteCaller(8080)
var reply string
err := caller.Call("MyHandler.MethodName", "argument", &reply)
if err != nil {
log.Fatal(err)
}
type RemoteListener ¶
type RemoteListener struct {
// contains filtered or unexported fields
}
RemoteListener represents a server that listens for remote procedure calls (RPC).
Fields:
- handler: The handler object that provides methods to be exposed via RPC.
- port: The port number on which the server listens for incoming connections.
func NewRemoteListener ¶
func NewRemoteListener(port int) *RemoteListener
NewRemoteListener creates a new instance of RemoteListener.
Parameters:
- port: The port number on which the server will listen.
Returns:
- A pointer to a new RemoteListener instance.
func (*RemoteListener) Run ¶
func (r *RemoteListener) Run()
Run starts the RemoteListener server.
This method registers the handler object for RPC, sets up an HTTP handler for RPC, and starts listening for incoming connections on the specified port.
Logs fatal errors if the server fails to start or encounters issues.
Example:
listener := NewRemoteListener(8080)
listener.SetHandler(&MyHandler{})
listener.Run()
func (*RemoteListener) SetHandler ¶
func (r *RemoteListener) SetHandler(Handler any)
SetHandler sets the handler object for the RemoteListener.
The handler object must have exported methods that can be called via RPC.
Parameters:
- Handler: The handler object to be registered for RPC.