inet

package
v0.0.0-...-aed9a31 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2023 License: Unlicense Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConnectionHanged  = errors.New("connection is hanged")
	ErrConnectionClosed  = errors.New("connection is closed")
	ErrIllegalMsgType    = errors.New("illegal message type")
	ErrTooManyConnection = errors.New("too many connection")
)

Functions

func ToString

func ToString(value any) string

ToString convert value to string for number, string, []byte, will convert to string for other type (slice, map, array, struct) will call json.Marshal

Types

type BeforeUpgradeHandle

type BeforeUpgradeHandle func(w http.ResponseWriter, r *http.Request) bool

type Client

type Client interface {
	// Dial 拨号连接
	Dial() (Conn, error)
	// OnConnect 监听连接打开
	OnConnect(handler ConnectHandler)
	// OnReceive 监听接收消息
	OnReceive(handler ReceiveHandler)
	// OnDisconnect 监听连接断开
	OnDisconnect(handler DisconnectHandler)
}

type CloseHandler

type CloseHandler func()

type Codec

type Codec interface {
	Marshal(v interface{}) ([]byte, error)
	Unmarshal(data []byte, v interface{}) error
}

type Conn

type Conn interface {
	// ID 获取连接ID
	ID() string
	// UID 获取用户ID
	UID() int
	// Bind 绑定用户ID
	Bind(uid int)
	// Unbind 解绑用户ID
	Unbind()
	// Send 发送消息(同步)
	Send(data []byte, msgType ...int) error
	// Push 发送消息(异步)
	Push(data []byte, msgType ...int) (err error)
	// PushAll 全网关发送(异步)
	PushAll(data []byte, smgType ...int) error
	// State 获取连接状态
	State() ConnState
	// Close 关闭连接
	Close(isForce ...bool) error
	// LocalIP 获取本地IP
	LocalIP() (string, error)
	// LocalAddr 获取本地地址
	LocalAddr() (net.Addr, error)
	// RemoteIP 获取远端IP
	RemoteIP() (string, error)
	// RemoteAddr 获取远端地址
	RemoteAddr() (net.Addr, error)

	MateCache
}

type ConnMgr

type ConnMgr interface {
	Each(fn func(conn Conn) bool)
	GetConn(id string) Conn
}

type ConnState

type ConnState int32
const (
	ConnOpened ConnState = iota + 1 // 连接打开
	ConnHanged                      // 连接挂起
	ConnClosed                      // 连接关闭
)

type ConnectHandler

type ConnectHandler func(conn Conn)

type DisconnectHandler

type DisconnectHandler func(conn Conn)

type IRouter

type IRouter interface {
	RegisterHandle(msgId int32, param interface{}, fn interface{})
	RegisterMsg(msgId int32, msg interface{})
	LoadRouterInfo(msgId int32) IRouterInfo
	LoadMsgId(responseMsg interface{}) int32
}

type IRouterInfo

type IRouterInfo interface {
	GetMsgID() int32
	GetMethod() reflect.Value
	GetParam() reflect.Type
	SetMsgID(msgID int32)
	SetMethod(method reflect.Value)
	SetParam(param reflect.Type)
}

type MateCache

type MateCache interface {
	GetMateData(string) any
	DelMateData(string)
	SetMetaData(k string, v any)
	GetMetaDataAll() map[string]any
}

type MetaStorage

type MetaStorage interface {
	Storage(uid any, m map[string]any) error
	Delete(uid any) error
	Select(uid any) (map[string]any, error)
}

MetaStorage 缓存用户零时数据,用作断线重连等

type Packer

type Packer interface {
	// Pack 打包消息
	Pack(mid int32, data []byte) ([]byte, error)
	// Unpack 解包消息
	Unpack(data []byte) (int32, []byte, error)
}

type ReceiveHandler

type ReceiveHandler func(conn Conn, msg []byte)

type Server

type Server interface {
	// Addr 监听地址
	Addr() string
	// Start 启动服务器
	Start() error
	// Stop 关闭服务器
	Stop() error
	// OnStart 监听服务器启动
	OnStart(handler StartHandler)
	// OnStop 监听服务器关闭
	OnStop(handler CloseHandler)
}

type SocketServer

type SocketServer interface {
	// Addr 监听地址
	Addr() string
	// Start 启动服务器
	Start() error
	// Stop 关闭服务器
	Stop() error
	// OnStart 监听服务器启动
	OnStart(handler StartHandler)
	// OnStop 监听服务器关闭
	OnStop(handler CloseHandler)
	// OnConnect 监听连接打开
	OnConnect(handler ConnectHandler)
	// OnReceive 监听接收消息
	OnReceive(handler ReceiveHandler)
	// OnDisconnect 监听连接断开
	OnDisconnect(handler DisconnectHandler)
	//GetConnMgr 获取连接管理器
	GetConnMgr() ConnMgr
	// Protocol 协议
	Protocol() string
	// SetCacheStorage 设置缓存存储函数
	SetCacheStorage(storage MetaStorage)
}

type StartHandler

type StartHandler func()

Jump to

Keyboard shortcuts

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