socket2

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2022 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	ClientId string // 我的客户端id

	OnMessage     func(msg UDataSocket, C *Client) // 消息回调
	OnConnect     func(C *Client)                  // 上线回调
	OnConnectFail func(C *Client)                  // 上线回调
	OnDisConnect  func(C *Client)                  // 掉线回调
	// contains filtered or unexported fields
}

客户端结构体

func NewClient

func NewClient(ip string, port int, OnMessage func(msg UDataSocket, C *Client), OnConnectFail, OnConnect, OnDisConnect func(C *Client)) *Client

对外函数1:初始化一个客户端

func (*Client) Connect

func (Me *Client) Connect()

对外函数3:连接服务器

func (*Client) DisConnect

func (Me *Client) DisConnect()

对外函数6:主动断开连接

func (*Client) ReConnect

func (Me *Client) ReConnect(second int)

对外函数3:延时后重连

func (*Client) SendMsg

func (Me *Client) SendMsg(msg UDataSocket) error

对外函数5:消息发送

func (*Client) Set

func (Me *Client) Set(opt string, value interface{})

对外函数2:连接服务器

type HookEvent

type HookEvent struct {
	EventType string // 事件类型 online / offline / message
	User      *serverUser
	Message   UDataSocket
}

结构体2:hook消息结构体

type Server

type Server struct {
	Ip                 string
	Port               int
	ClientHeartTimeOut int                 // 客户端超时时间 默认60秒
	OnHookEvent        func(Msg HookEvent) // hook回调消息
	ChanHookEvent      chan *HookEvent     // 所有消息,各个子连接传过来的

	SendFlag int // socket验证标记
	// contains filtered or unexported fields
}

结构体1:服务结构体数据

func NewServer

func NewServer(ip string, port int, OnHookEvent func(Msg HookEvent)) *Server

对外函数1:创建一个server的实例

func (*Server) SendMsg

func (Me *Server) SendMsg(ClientId *string, Msg UDataSocket) error

对外函数2:消息发送,ClientId为nil,发给所有客户端

func (*Server) Set

func (Me *Server) Set(opt string, value interface{})

对外函数2:连接服务器

type UDataSocket

type UDataSocket struct {
	Zlib    int8   // 是否压缩 1:压缩
	CType   int16  // 内容类型 1:客户端请求消息 2:服务端表接口消息 4:服务端表内容数据 200:服务端发送结束
	Content []byte // 发送内容
}

结构体1:(外部用)传输数据上层结构体

Jump to

Keyboard shortcuts

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