tcp

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrIncompletePacket = errors.New("incomplete packet")

Functions

This section is empty.

Types

type Builder

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

func NewBuilder

func NewBuilder() *Builder

func (*Builder) Build

func (b *Builder) Build(target string) (*Client, error)

Build 构建连接

func (*Builder) OnClientDisconnected

func (b *Builder) OnClientDisconnected(target string)

func (*Builder) Update

func (b *Builder) Update(endpoints map[string]bool)

type Client

type Client struct {
	Connected         bool
	Target            string
	DisconnectHandler transport.DisconnectHandler
	// contains filtered or unexported fields
}

func NewClient

func NewClient(target string) (*Client, error)

func (*Client) ForceClose

func (c *Client) ForceClose(err error)

func (*Client) Next

func (c *Client) Next() uint32

func (*Client) Receive

func (c *Client) Receive() (methodName uint16, messageId uint32, data []byte, err error)

Receive 读取连接数据

func (*Client) Send

func (c *Client) Send(methodName uint16, req proto.Message) (err error)

func (*Client) SendWithReply

func (c *Client) SendWithReply(methodName uint16, req proto.Message) (replyPacket *ReplyPacket, err error)

type CommonResponse

type CommonResponse struct {
	Route     uint16
	MessageId uint32
	Data      []byte
}

type Options

type Options struct {
	Discovery registry.Discovery
}

type ReplyPacket

type ReplyPacket struct {
	MessageId  uint32
	MethodName uint16
	ReplyCh    chan []byte
	Req        proto.Message
}

type Server

type Server struct {
	gnet.BuiltinEventEngine
	// contains filtered or unexported fields
}

func NewServer

func NewServer(addr string) *Server

func (*Server) OnBoot

func (s *Server) OnBoot(eng gnet.Engine) (action gnet.Action)

func (*Server) OnClose

func (s *Server) OnClose(c gnet.Conn, err error) (action gnet.Action)

func (*Server) OnOpen

func (s *Server) OnOpen(c gnet.Conn) (out []byte, action gnet.Action)

func (*Server) OnReceive

func (s *Server) OnReceive(handler transport.ReceiveHandler)

OnReceive 监听接收到消息

func (*Server) OnTraffic

func (s *Server) OnTraffic(c gnet.Conn) (action gnet.Action)

func (*Server) Start

func (s *Server) Start()

func (*Server) Stop

func (s *Server) Stop()

type SimpleCodec

type SimpleCodec struct{}

SimpleCodec Protocol format:

* 0 4 * +-----------+-----------------------+ * | body len | * | methodName | * | message id | * +-----------+-----------+-----------+ * | | * + + * | body bytes | * + + * | ... ... | * +-----------------------------------+

func (*SimpleCodec) Decode

func (codec *SimpleCodec) Decode(c gnet.Conn) (*CommonResponse, error)

func (SimpleCodec) Encode

func (codec SimpleCodec) Encode(route uint16, messageId uint32, buf []byte) ([]byte, error)

func (SimpleCodec) Unpack

func (codec SimpleCodec) Unpack(buf []byte) ([]byte, error)

type WriteChPacket

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

Jump to

Keyboard shortcuts

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