tcp

package
v0.0.0-...-d098e83 Latest Latest
Warning

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

Go to latest
Published: May 23, 2021 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 {
	OnEventPacket  OnEventPacketClientFunc
	OnEventDisConn OnEventDisConnClientFunc
	Remote         Remote
	// contains filtered or unexported fields
}

己方作为客户端

func (*Client) Connect

func (p *Client) Connect(address string, recvPacketMaxLen uint32, tcpChan chan<- interface{},
	OnEventDisConn OnEventDisConnClientFunc,
	OnEventPacket OnEventPacketClientFunc,
	onParseProtoHead OnParseProtoHeadFunc,
	sendChanCapacity uint32) (err error)

连接 每个连接有一个 发送协程, 一个 接收协程 事件放入 参数 eventChan 中, 以供外部处理 recvPacketMaxLen:接受数据包的最大长度(包头+包体) tcpChan:外部传递的事件处理管道.连接的事件会放入该管道,以供外部处理 sendChanCapacity:发送管道容量

func (*Client) DisConn

func (p *Client) DisConn() (err error)

主动断开连接

func (*Client) EventDisConn

func (p *Client) EventDisConn()

事件中处理时调用

func (*Client) IsConn

func (p *Client) IsConn() bool

type EventConnServer

type EventConnServer struct {
	Server *Server
	Remote *Remote
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// server 链接成功事件

type EventDisConnClient

type EventDisConnClient struct {
	Client *Client
}

断开链接事件

type EventDisConnServer

type EventDisConnServer struct {
	Server *Server
	Remote *Remote
}

断开链接事件

type EventPacketClient

type EventPacketClient struct {
	Client *Client
	Data   []byte
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// client 数据包事件

type EventPacketServer

type EventPacketServer struct {
	Server *Server
	Remote *Remote
	Data   []byte
}

数据包事件

type OnEventConnServerFunc

type OnEventConnServerFunc func(remote *Remote) int

处理链接成功事件

type OnEventDefaultFunc

type OnEventDefaultFunc func(v interface{}) int

type OnEventDisConnClientFunc

type OnEventDisConnClientFunc func(client *Client) int

处理断开链接事件

type OnEventDisConnServerFunc

type OnEventDisConnServerFunc func(remote *Remote) int

处理断开链接事件

type OnEventPacketClientFunc

type OnEventPacketClientFunc func(client *Client, data []byte) int

处理数据包事件

type OnEventPacketServerFunc

type OnEventPacketServerFunc func(remote *Remote, data []byte) int

处理数据包事件

type OnParseProtoHeadFunc

type OnParseProtoHeadFunc func(data []byte, length int) int

解析协议包头 返回长度:完整包总长度 返回0:不是完整包 返回-1:包错误

type Remote

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

远端信息

func (*Remote) IsConn

func (p *Remote) IsConn() bool

是否连接

func (*Remote) Send

func (p *Remote) Send(data []byte) (err error)

发送数据(data 数据不可修改)(必须在处理EventChan事件中调用)

type Server

type Server struct {
	OnConn    OnEventConnServerFunc
	OnPacket  OnEventPacketServerFunc
	OnDisconn OnEventDisConnServerFunc
	// contains filtered or unexported fields
}

func (*Server) DisConn

func (p *Server) DisConn(remote *Remote) (err error)

主动断开连接

func (*Server) EventDisconn

func (p *Server) EventDisconn(remote *Remote)

处理事件时调用

func (*Server) Stop

func (p *Server) Stop()

停止 AcceptTCP

func (*Server) Strat

func (p *Server) Strat(address string, recvPacketMaxLen uint32, eventChan chan<- interface{},
	onConn OnEventConnServerFunc,
	onDisconn OnEventDisConnServerFunc,
	onPacket OnEventPacketServerFunc,
	onParseProtoHead OnParseProtoHeadFunc,
	sendChanCapacity uint32) (err error)

运行服务 rwBuffLen:tcp recv/send 缓冲大小 recvPacketMaxLen:最大包长(包头+包体) eventChan:外部传递的事件处理

Jump to

Keyboard shortcuts

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