client

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2022 License: MulanPSL-2.0 Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback struct {
	OnDebug func(string)

	OnError func(string, error, Client, server.Message)
}

回调函数集封装

func (*Callback) TrigDebug

func (rc *Callback) TrigDebug(str string)

func (*Callback) TrigError

func (rc *Callback) TrigError(s string, e error, r Client, m server.Message)

type Client

type Client interface {
	ID() uint64
	Local() string
	Close()

	Send(msg server.Message) error
	Recv() (server.Message, error)
}

客户端抽象定义

type ClientContext

type ClientContext struct {
	MessageProtocol server.MessageProtocol

	CB *Callback

	TCPConnectionConfig *TCPConnectionConfig
	UDPConnectionConfig *UDPConnectionConfig
}

客户端上下文

type OrigUDPConnection added in v0.0.2

type OrigUDPConnection struct {
	Conn *net.UDPConn
}

UDP原始连接的简单封装

func (*OrigUDPConnection) Close added in v0.0.2

func (ouc *OrigUDPConnection) Close() error

func (*OrigUDPConnection) ReadFromUDP added in v0.0.2

func (ouc *OrigUDPConnection) ReadFromUDP() ([]byte, *net.UDPAddr, error)

func (*OrigUDPConnection) SendToUDP added in v0.0.2

func (ouc *OrigUDPConnection) SendToUDP(addr *net.UDPAddr, bs []byte) error

func (*OrigUDPConnection) TryGetConnID added in v0.0.2

func (oc *OrigUDPConnection) TryGetConnID(remote *net.UDPAddr, timeout time.Duration) (uint64, error)

尝试发送消息获取逻辑连接的ID

type TCPAsyncClient

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

客户端的TCP异步实现

func DialTCPAsyncClient

func DialTCPAsyncClient(address string, ctx *ClientContext, id uint64) (*TCPAsyncClient, error)

构造客户端并连接远程服务 将启动两个goroutine进行消息收发

func (*TCPAsyncClient) Close

func (c *TCPAsyncClient) Close()

func (*TCPAsyncClient) ID

func (c *TCPAsyncClient) ID() uint64

func (*TCPAsyncClient) Local

func (c *TCPAsyncClient) Local() string

func (*TCPAsyncClient) Recv

func (c *TCPAsyncClient) Recv() (server.Message, error)

异步接收消息. 从消息缓冲区中读一个消息, 缓冲区空时立刻返回返回nil

func (*TCPAsyncClient) RecvChan

func (c *TCPAsyncClient) RecvChan() <-chan server.Message

直接使用接收消息缓冲队列

func (*TCPAsyncClient) Send

func (c *TCPAsyncClient) Send(msg server.Message) error

异步发送消息. 推入消息发送缓冲区

type TCPConnectionConfig added in v0.0.2

type TCPConnectionConfig struct {
	*server.TCPConnectionConfig
}

type TCPSyncClient

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

客户端的TCP同步型

func DialTCPSyncClient

func DialTCPSyncClient(address string, ctx *ClientContext, id uint64) (*TCPSyncClient, error)

构造客户端并连接远程服务

func (*TCPSyncClient) Close

func (c *TCPSyncClient) Close()

func (*TCPSyncClient) ID

func (c *TCPSyncClient) ID() uint64

func (*TCPSyncClient) Local

func (c *TCPSyncClient) Local() string

func (*TCPSyncClient) Recv

func (c *TCPSyncClient) Recv() (server.Message, error)

阻塞地接收消息

func (*TCPSyncClient) Send

func (c *TCPSyncClient) Send(msg server.Message) error

阻塞地发送消息

type UDPAsyncClient added in v0.0.2

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

客户端的UDP异步实现

func DialUDPAsyncClient added in v0.0.2

func DialUDPAsyncClient(address string, ctx *ClientContext) (*UDPAsyncClient, error)

构造客户端并连接远程服务 将启动两个goroutine进行消息收发, 以及一个读取udp分片消息的goroutine

func (*UDPAsyncClient) Close added in v0.0.2

func (c *UDPAsyncClient) Close()

func (*UDPAsyncClient) ID added in v0.0.2

func (c *UDPAsyncClient) ID() uint64

func (*UDPAsyncClient) Local added in v0.0.2

func (c *UDPAsyncClient) Local() string

func (*UDPAsyncClient) Recv added in v0.0.2

func (c *UDPAsyncClient) Recv() (server.Message, error)

异步接收消息. 从消息缓冲区中读一个消息, 缓冲区空时立刻返回返回nil

func (*UDPAsyncClient) RecvChan added in v0.0.2

func (c *UDPAsyncClient) RecvChan() <-chan server.Message

直接使用接收消息缓冲队列

func (*UDPAsyncClient) Send added in v0.0.2

func (c *UDPAsyncClient) Send(msg server.Message) error

异步发送消息. 推入消息发送缓冲区

type UDPConnectionConfig added in v0.0.2

type UDPConnectionConfig struct {
	*server.UDPConnectionConfig

	TimeoutDialMS int
}

UDP连接配置

type UDPSyncClient added in v0.0.2

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

客户端的UDP同步型

func DialUDPSyncClient added in v0.0.2

func DialUDPSyncClient(address string, ctx *ClientContext) (*UDPSyncClient, error)

构造客户端并连接远程服务 其中包含一个用于读取udp分片消息的goroutine

func (*UDPSyncClient) Close added in v0.0.2

func (c *UDPSyncClient) Close()

func (*UDPSyncClient) ID added in v0.0.2

func (c *UDPSyncClient) ID() uint64

func (*UDPSyncClient) Local added in v0.0.2

func (c *UDPSyncClient) Local() string

func (*UDPSyncClient) Recv added in v0.0.2

func (c *UDPSyncClient) Recv() (server.Message, error)

阻塞地接收消息

func (*UDPSyncClient) Send added in v0.0.2

func (c *UDPSyncClient) Send(msg server.Message) error

阻塞地发送消息

Directories

Path Synopsis
sample

Jump to

Keyboard shortcuts

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