websocket

package
v0.0.0-...-07235e0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2017 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package websocket 提供WebSocket服务

Index

Constants

View Source
const (
	// ServerName 服务名
	ServerName = "websocket"
)

Variables

View Source
var (
	// HeartBeatCommand 心跳命令
	HeartBeatCommand = &protocol.Command{
		Name: protocol.HeartBeat,
	}
	// HeartBeatResponseCommand 心跳响应命令
	HeartBeatResponseCommand = &protocol.Command{
		Name: protocol.HeartBeatResponse,
	}
)

Functions

This section is empty.

Types

type Connection

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

Connection 连接

func NewConnection

func NewConnection(c *websocket.Conn) *Connection

NewConnection 新建连接

func (*Connection) AppID

func (conn *Connection) AppID() string

AppID 应用ID

func (*Connection) Close

func (conn *Connection) Close(force bool) error

Close 关闭链接(define::Connection接口函数)

func (*Connection) DeviceID

func (conn *Connection) DeviceID() string

DeviceID 设备ID

func (*Connection) ID

func (conn *Connection) ID() string

ID 连接ID

func (*Connection) IsLogin

func (conn *Connection) IsLogin() bool

IsLogin 登入状态

func (*Connection) LoginSuccess

func (conn *Connection) LoginSuccess(appID, userID, deviceID, defaultVersion string)

LoginSuccess 登入成功

func (*Connection) ReadCommand

func (conn *Connection) ReadCommand() (cmd *protocol.Command, err error)

ReadCommand 读取命令

func (*Connection) Send

func (conn *Connection) Send(cmd *protocol.Command) error

Send 发送命令

func (*Connection) String

func (conn *Connection) String() string

ToString 字符串输出(define::Connection接口函数)

func (*Connection) UserID

func (conn *Connection) UserID() string

UserID 用户ID

type Server

type Server struct {
	// WSParameter WebSocket服务构造参数
	WSParameter
	// contains filtered or unexported fields
}

Server WebSocket服务

func NewServer

func NewServer(serverHandler define.ServerHandler) (srv *Server, err error)

NewServer 新建一个WebSocket服务实例

func (*Server) Close

func (srv *Server) Close(timeout time.Duration) (err error)

Close 退出

func (*Server) HandleDebug

func (srv *Server) HandleDebug(w http.ResponseWriter, r *http.Request)

HandleDebug 处理HTTP链接

func (*Server) HandleWebSocket

func (srv *Server) HandleWebSocket(w http.ResponseWriter, r *http.Request)

HandleWebSocket 处理HTTP链接

func (*Server) Run

func (srv *Server) Run(ctx context.Context) (err error)

Run 启动WebSocket服务

func (*Server) ServeHTTP

func (srv *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

Handle 处理HTTP链接

type WSParameter

type WSParameter struct {
	// WSBindAddress WebSocket服务绑定地址
	WSBindAddress string
	// WSSBindAddress WebSocket服务绑定地址
	WSSBindAddress string
	// Debug 调试模式
	Debug bool
	// CertFile 证书文件
	CertFile string
	// KeyFile 密钥文件
	KeyFile string
}

WSParameter WebSocket服务构造参数

Jump to

Keyboard shortcuts

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