socket_v1

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2021 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetSendFlag added in v1.0.4

func SetSendFlag(Flag int)

设置函数: 密码设置,服务端和客户端需要约定好;不设置则使用默认的

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

对外函数2:连接服务器

func (*Client) ReConnect

func (Me *Client) ReConnect(second int)

对外函数3:延时后重连

func (*Client) SendMsg

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

对外函数4:消息发送

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
	OnlineMap          map[string]*serverUser // 在线用户的列表
	ClientHeartTimeOut int                    // 客户端超时时间 默认60秒
	OnHookEvent        func(Msg HookEvent)    // hook回调消息
	ChanHookEvent      chan *HookEvent        // 所有消息,各个子连接传过来的

	MapLock sync.RWMutex // 同步锁
	// 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,发给所有客户端

type UDataSocket

type UDataSocket struct {
	Zlib    int    // 是否压缩 1:压缩
	CType   int    // 内容类型 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