client

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client added in v0.1.0

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

Client 客户端

func CloneClient added in v0.1.2

func CloneClient(client *Client) *Client

CloneClient 克隆客户端

func NewClient added in v0.1.0

func NewClient(core Core) *Client

NewClient 创建客户端

func NewTCP added in v0.1.1

func NewTCP(addr string) *Client

func NewUnixDomainSocket added in v0.0.31

func NewUnixDomainSocket(addr string) *Client

func NewWebsocket

func NewWebsocket(addr string) *Client

NewWebsocket 创建 websocket 客户端

func (*Client) Close added in v0.1.0

func (slf *Client) Close(err ...error)

Close 关闭

func (*Client) GetServerAddr added in v0.1.0

func (slf *Client) GetServerAddr() string

GetServerAddr 获取服务器地址

func (*Client) IsConnected added in v0.1.0

func (slf *Client) IsConnected() bool

IsConnected 是否已连接

func (Client) OnConnectionClosedEvent added in v0.1.0

func (slf Client) OnConnectionClosedEvent(conn *Client, err any)

func (Client) OnConnectionOpenedEvent added in v0.1.0

func (slf Client) OnConnectionOpenedEvent(conn *Client)

func (Client) OnConnectionReceivePacketEvent added in v0.1.0

func (slf Client) OnConnectionReceivePacketEvent(conn *Client, wst int, packet []byte)

func (Client) RegConnectionClosedEvent added in v0.1.0

func (slf Client) RegConnectionClosedEvent(handle ConnectionClosedEventHandle)

RegConnectionClosedEvent 注册连接关闭事件

func (Client) RegConnectionOpenedEvent added in v0.1.0

func (slf Client) RegConnectionOpenedEvent(handle ConnectionOpenedEventHandle)

RegConnectionOpenedEvent 注册连接打开事件

func (Client) RegConnectionReceivePacketEvent added in v0.1.0

func (slf Client) RegConnectionReceivePacketEvent(handle ConnectionReceivePacketEventHandle)

RegConnectionReceivePacketEvent 注册连接接收数据包事件

func (*Client) Run added in v0.1.0

func (slf *Client) Run(block ...bool) error

Run 运行客户端,当客户端已运行时,会先关闭客户端再重新运行

  • block 以阻塞方式运行

func (*Client) Write added in v0.1.0

func (slf *Client) Write(packet []byte, callback ...func(err error))

Write 向连接中写入数据

func (*Client) WriteWS added in v0.1.0

func (slf *Client) WriteWS(wst int, packet []byte, callback ...func(err error))

WriteWS 向连接中写入指定 websocket 数据类型

  • wst: websocket模式中指定消息类型

type ConnectionClosedEventHandle

type ConnectionClosedEventHandle func(conn *Client, err any)

type ConnectionOpenedEventHandle

type ConnectionOpenedEventHandle func(conn *Client)

type ConnectionReceivePacketEventHandle

type ConnectionReceivePacketEventHandle func(conn *Client, wst int, packet []byte)

type Core added in v0.1.0

type Core interface {
	// Run 启动客户端
	//  - runState: 运行状态,当客户端启动完成时,应该向该通道发送 error 或 nil
	//  - receive: 接收到数据包时应该将数据包发送到该函数,wst 表示 websocket 的数据类型,data 表示数据包
	Run(runState chan<- error, receive func(wst int, packet []byte))

	// Write 向客户端写入数据包
	Write(packet *Packet) error

	// Close 关闭客户端
	Close()

	// GetServerAddr 获取服务器地址
	GetServerAddr() string

	// Clone 克隆客户端
	Clone() Core
}

type Packet added in v0.0.31

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

type TCP added in v0.1.1

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

func (*TCP) Clone added in v0.1.2

func (slf *TCP) Clone() Core

func (*TCP) Close added in v0.1.1

func (slf *TCP) Close()

func (*TCP) GetServerAddr added in v0.1.1

func (slf *TCP) GetServerAddr() string

func (*TCP) Run added in v0.1.1

func (slf *TCP) Run(runState chan<- error, receive func(wst int, packet []byte))

func (*TCP) Write added in v0.1.1

func (slf *TCP) Write(packet *Packet) error

type UnixDomainSocket added in v0.0.31

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

func (*UnixDomainSocket) Clone added in v0.1.2

func (slf *UnixDomainSocket) Clone() Core

func (*UnixDomainSocket) Close added in v0.0.31

func (slf *UnixDomainSocket) Close()

func (*UnixDomainSocket) GetServerAddr added in v0.1.0

func (slf *UnixDomainSocket) GetServerAddr() string

func (*UnixDomainSocket) Run added in v0.0.31

func (slf *UnixDomainSocket) Run(runState chan<- error, receive func(wst int, packet []byte))

func (*UnixDomainSocket) Write added in v0.0.31

func (slf *UnixDomainSocket) Write(packet *Packet) error

type Websocket

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

Websocket websocket 客户端

func (*Websocket) Clone added in v0.1.2

func (slf *Websocket) Clone() Core

func (*Websocket) Close

func (slf *Websocket) Close()

func (*Websocket) GetServerAddr added in v0.1.0

func (slf *Websocket) GetServerAddr() string

func (*Websocket) Run

func (slf *Websocket) Run(runState chan<- error, receive func(wst int, packet []byte))

func (*Websocket) Write

func (slf *Websocket) Write(packet *Packet) error

Jump to

Keyboard shortcuts

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