sockUtils

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MulanPSL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataPack

type DataPack struct {
	Head  interface{}
	Datas []byte
}

type DefaultHeadHandler

type DefaultHeadHandler struct {
}

func (*DefaultHeadHandler) GetSize

func (d *DefaultHeadHandler) GetSize() uint32

func (*DefaultHeadHandler) ReadHead

func (d *DefaultHeadHandler) ReadHead(bits []byte, head *HeadInfo) bool

func (*DefaultHeadHandler) WriteHead

func (d *DefaultHeadHandler) WriteHead(bits []byte, head *HeadInfo) bool

type FastLocker

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

func (*FastLocker) Lock

func (l *FastLocker) Lock()

func (*FastLocker) Unlock

func (l *FastLocker) Unlock()

type HeadInfo

type HeadInfo struct {
	Head    interface{}
	BodyLen uint32
	SockId  int32 // 当前的连接,可以读到 SockId,服务器会用到
}

type IMsgHandler

type IMsgHandler interface {
	OnConnect(sock SocketConnection)
	OnDisconnect(sock SocketConnection)
	OnMessage(sock SocketConnection, msg *DataPack)
}

type IPackHeader

type IPackHeader interface {
	GetSize() uint32
	ReadHead(bits []byte, Head *HeadInfo) bool
	WriteHead(bits []byte, Head *HeadInfo) bool
}

type MsgBody

type MsgBody struct {
	MsgHead interface{}
	Datas   []byte
	// contains filtered or unexported fields
}

type MsgHeader

type MsgHeader struct {
	HeadInfo
	// contains filtered or unexported fields
}

type SockOptions

type SockOptions struct {
	HeadHandler    IPackHeader
	MsgHandler     IMsgHandler
	SockBufferSize uint32
}

type SocketClient

type SocketClient interface {
	Open()  // 开始连接,打开会会自动连接
	Close() // 关闭连接
	GetConnection() SocketConnection
	Connected() bool // 判断是否连接
}

func NewSocketClient

func NewSocketClient(addr string, avOpts SockOptions) SocketClient

type SocketConnection

type SocketConnection interface {
	SendMsg(packHead interface{}, avBytes []byte) bool
	// SendData(data []byte)
	RemoteAddr() net.Addr
	GetId() int32
	Disconnect()
	GetData() interface{}
	SetData(usrData interface{})
}

type SocketServer

type SocketServer interface {
	Open(avPort uint16) bool                                        // 开启服务
	Close()                                                         // 关闭
	Foreach(f enum_callback)                                        // 遍历连接
	SendMsg(SockId int32, msgHead interface{}, avBytes []byte) bool // 根据id 发送消息
	SendData(SockId int32, Data []byte) bool                        // 直接发送数据
	GetConnectCount() int32                                         // 获取连接总数
}

func NewSocketServer

func NewSocketServer(avOpts SockOptions) SocketServer

Jump to

Keyboard shortcuts

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