rpc

package
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 1, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client 表示与远程服务进行通信的客户端

func NewClient

func NewClient() *Client

NewClient 创建一个新的客户端

func (*Client) Call

func (this *Client) Call(v []interface{}) []interface{}

Call 发起远程调用并等待结果

func (*Client) Close added in v0.0.6

func (this *Client) Close(uint16)

Close 关闭客户端

func (*Client) Connect added in v0.0.6

func (this *Client) Connect(fd uint16, s *network.Session)

Connect 建立客户端会话

func (*Client) Dial

func (this *Client) Dial(addr string)

Dial 连接到远程服务器

func (*Client) Heartbeat added in v0.0.6

func (this *Client) Heartbeat(fd uint16, sessionID uint16)

Heartbeat 心跳处理

func (*Client) Message added in v0.0.6

func (this *Client) Message(fd uint16, sessionID uint16, body []byte)

Message 处理从服务器接收到的消息

func (*Client) Send

func (this *Client) Send(v []interface{})

Send 发送数据到服务器,无需等待响应

func (*Client) SendCallBack added in v0.0.6

func (this *Client) SendCallBack(v []interface{}, callBack func(callRet interface{}))

SendCallBack 发送数据到服务器,并在收到响应后执行回调函数

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server 表示RPC服务器,用于处理远程过程调用请求。 它维护了一个服务映射(serviceMap),包含了注册的RPC服务。 该服务器还包含一个TCP服务器(tcpServer),用于处理网络连接。 以及一个会话映射(sessions),用于跟踪和管理客户端会话。

func NewServer

func NewServer(addr string) *Server

NewServer 创建一个新的RPC服务器实例。 参数 addr 是服务器监听的地址,通常是 IP 地址和端口号,例如 "localhost:8080"。 该函数会初始化一个服务映射(serviceMap),一个TCP服务器(tcpServer),以及一个会话映射(sessions)。 返回一个指向新服务器实例的指针。

func (*Server) Close added in v0.0.6

func (this *Server) Close(fd uint16)

Close 处理连接关闭。

func (*Server) Connect added in v0.0.6

func (this *Server) Connect(fd uint16, session *network.Session)

Connect 处理新连接。

func (*Server) Heartbeat added in v0.0.6

func (this *Server) Heartbeat(fd uint16, sessionID uint16)

Heartbeat 处理心跳消息。

func (*Server) Message added in v0.0.6

func (this *Server) Message(fd uint16, sessionID uint16, body []byte)

Message 处理接收到的消息。

func (*Server) Register

func (this *Server) Register(rcvr interface{})

Register 注册一个RPC服务。 参数 rcvr 是一个接收器(receiver)对象,该对象包含了实现RPC方法的函数。 该方法会为接收器对象创建一个服务实例,并将服务名称、方法信息等注册到服务器。

func (*Server) RunFunc

func (this *Server) RunFunc(m *methodType, args []reflect.Value) []interface{}

RunFunc 执行注册的RPC方法。 参数 m 表示要执行的方法信息,args 表示方法的参数值列表。 返回一个包含方法执行结果的切片,每个元素都是方法的返回值。

func (*Server) Start added in v0.0.6

func (this *Server) Start()

Start 启动服务器。

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service 表示一个RPC服务,它包含了一个接收器(receiver)对象,该对象拥有RPC方法。 服务通常由名称标识,并且可以包含多个注册的RPC方法。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL