ws

package
v0.0.0-...-a76d67b Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2019 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

****************************************************** WebSocket Client连接对象 Author :Jella Version :1.0.2(release) Dependency :github.com/gorilla/websocket ******************************************************

Index

Constants

This section is empty.

Variables

View Source
var (

	//连接对象
	Sessions sync.Map
)

内部变量

Functions

func Broadcast

func Broadcast(data []byte)

*

  • 广播消息
  • @param data 消息

func Listen

func Listen(conf WSConfig, mhandler messageHandler)

*

  • 启动WebSocket监听服务
  • @param conf websocket服务启动配置
  • @param mhandler 消息处理函数(函数应有2个参数,参数类型分别 *ws.Session,[]byte。第1个参数是与客户端的连接对象,第2个是消息数据)

func ShutdownClient

func ShutdownClient(k string)

*

  • 服务主动关闭一个客户端连接对象
  • @param k session的索引值

Types

type Session

type Session struct {
	RemoteAddress string

	//其他
	Params interface{}
	// contains filtered or unexported fields
}

*

  • 连接对象结构体(应由服务来创建,外部不可手动创建)

func (*Session) Close

func (session *Session) Close()

*

  • 关闭Session连接 *

func (*Session) IsClosed

func (session *Session) IsClosed() bool

*

  • 连接是否处于关闭状态
  • @return true:关闭;false:打开

func (*Session) SendMessage

func (session *Session) SendMessage(data []byte)

*

  • 发送消息
  • @param data 数据

type WSClient

type WSClient struct {
	IsConnect bool
	// contains filtered or unexported fields
}

* websocket客户端

func (*WSClient) Close

func (client *WSClient) Close()

*

  • 关闭连接

func (*WSClient) Connect

func (client *WSClient) Connect(conf WSClient_CONFIG) error

*

  • 连接
  • @param conf 连接配置
  • @return 连接的错误。若没有错误则返回nil

func (*WSClient) OnClose

func (client *WSClient) OnClose(f wsClientClose)

*

  • 注册连接关闭回调

func (*WSClient) Reci

func (client *WSClient) Reci(handler wsClientReci)

*

  • 收取消息
  • @param handler 收取消息的回调函数(函数应有一个参数。参数类型[]byte。)

func (*WSClient) Send

func (client *WSClient) Send(data []byte)

*

  • 发送数据
  • @param data 数据内容

type WSClient_CONFIG

type WSClient_CONFIG struct {
	Host      string
	Port      int
	Path      string
	BufferLen int
}

* 连接配置

type WSConfig

type WSConfig struct {
	Host      string
	Port      int
	Pattern   string
	BufferLen int
}

*

  • WebSocket服务配置

Jump to

Keyboard shortcuts

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