Help us shape the future of Go! Take the 2026 Go Developer Survey

network

package
v2.4.4 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2025 License: MIT Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attr added in v2.3.1

type Attr interface {
	// Set 设置属性值
	Set(key, value any)
	// Get 获取属性值
	Get(key any) (any, bool)
	// Del 删除属性值
	Del(key any) bool
	// Visit 访问所有的属性值
	Visit(fn func(key, value any) bool)
}

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
	// Attr 属性接口
	Attr() Attr
	// 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, buf buffer.Buffer)

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