network

package
v2.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: MIT Imports: 1 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

type CloseHandler

type CloseHandler func()

type Conn

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

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 ReceiveHandler

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

type Server

type Server interface {
	// Addr 监听地址
	Addr() string
	// Start 启动服务器
	Start() error
	// Stop 关闭服务器
	Stop() error
	// Protocol 协议
	Protocol() string
	// OnStart 监听服务器启动
	OnStart(handler StartHandler)
	// OnStop 监听服务器关闭
	OnStop(handler CloseHandler)
	// OnConnect 监听连接打开
	OnConnect(handler ConnectHandler)
	// OnReceive 监听接收消息
	OnReceive(handler ReceiveHandler)
	// OnDisconnect 监听连接断开
	OnDisconnect(handler DisconnectHandler)
}

type StartHandler

type StartHandler func()

Jump to

Keyboard shortcuts

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