rpc

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2020 License: MIT Imports: 10 Imported by: 0

README

rpc.go

Documentation

Index

Constants

View Source
const (
	MessageTypeKeep  = MessageType(1)
	MessageTypeData  = MessageType(2)
	MessageTypeReply = MessageType(3)
)

Variables

View Source
var (
	ErrorMessageFormatInvalid = errors.New("message format invalid")
	ErrorConnectIdInvalid     = errors.New("connect id invalid")
	ErrorConnectionInvalid    = errors.New("connection invalid")
)

Functions

This section is empty.

Types

type AcceptClient

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

type Client

type Client struct {
	ReadTimeout  time.Duration
	WriteTimeout time.Duration

	OnConnected func()
	OnClose     func()
	OnData      func(message *Message)
	// contains filtered or unexported fields
}

func NewClient

func NewClient() (*Client, error)

func (*Client) Close

func (c *Client) Close()

func (*Client) DialAndServe

func (c *Client) DialAndServe(address string, password []byte, salt []byte) error

func (*Client) NextRequestId added in v1.0.3

func (c *Client) NextRequestId(cb func(*Message)) uint32

func (*Client) OnReply added in v1.0.3

func (c *Client) OnReply(msg *Message)

func (*Client) Reconnect

func (c *Client) Reconnect(second time.Duration)

func (*Client) Send

func (c *Client) Send(tag uint32, data []byte, cb func(*Message)) (err error)

type Message added in v1.0.3

type Message struct {
	Type    MessageType
	Payload []byte
	Tag     uint32
	// contains filtered or unexported fields
}

func (*Message) Reply added in v1.0.3

func (m *Message) Reply(tag uint32, payload []byte)

type MessageType

type MessageType uint8

type Server

type Server struct {
	ReadTimeout  time.Duration
	WriteTimeout time.Duration

	OnNew   func(id uint64)
	OnData  func(id uint64, message *Message)
	OnClose func(id uint64)
	// contains filtered or unexported fields
}

func NewServer

func NewServer() (*Server, error)

创建服务器

func (*Server) NextRequestId added in v1.0.3

func (s *Server) NextRequestId(cb func(*Message)) uint32

func (*Server) Send

func (s *Server) Send(id uint64, tag uint32, data []byte, cb func(*Message)) (n int, err error)

func (*Server) Serve

func (s *Server) Serve(address string, password []byte, salt []byte) error

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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