network

package
v0.0.34 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: MIT Imports: 2 Imported by: 5

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

This section is empty.

Types

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 Conn

type Conn interface {
	// ID 获取连接ID
	ID() int64
	// UID 获取用户ID
	UID() int64
	// Bind 绑定用户ID
	Bind(uid int64)
	// Unbind 解绑用户ID
	Unbind()
	// Send 发送消息(同步)
	Send(msg []byte, msgType ...int) error
	// Push 发送消息(异步)
	Push(msg []byte, msgType ...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)
	// Block 阻塞conn数据
	Block()
	// Release 释放conn数据·
	Release()
}

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, msgType int)

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()

Directories

Path Synopsis
gnet module
kcp module
netpoll module
tcp module
ws module

Jump to

Keyboard shortcuts

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