websocket

package
v0.0.0-...-93c743e Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2023 License: MIT Imports: 14 Imported by: 0

README

服务端server.go

  1. 握手升级,HTTP --> websocket
  2. newConn(net.conn) 将net.Conn包装成him.Conn
  3. r.Accept(conn, r.options.loginWait) 回调到上层业务完成权限认证
  4. r.Add(channel) 自动添加到him.ChannelMap连接管理器
  5. ch.ReadLoop(r.MessageListener) 开启一个goroutine中循环读取消息

客户端client.go

  1. Connect:拨号建立并连接握手
  2. heartbeatLoop:发送心跳
  3. Read:读取消息
  4. Send:发送消息

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClient

func NewClient(id, name string, opts ClientOptions) him.Client

func NewServer

func NewServer(listen string, service him.ServiceRegistration) him.Server

Types

type Client

type Client struct {
	sync.Mutex
	him.Dialer
	// contains filtered or unexported fields
}

Client is websocket client implement of the terminal

func (*Client) Close

func (c *Client) Close()

func (*Client) Connect

func (c *Client) Connect(addr string) error

func (*Client) GetMeta

func (c *Client) GetMeta() map[string]string

func (*Client) ID

func (c *Client) ID() string

func (*Client) Name

func (c *Client) Name() string

func (*Client) Read

func (c *Client) Read() (him.Frame, error)

func (*Client) Send

func (c *Client) Send(payload []byte) error

func (*Client) ServiceID

func (c *Client) ServiceID() string

func (*Client) ServiceName

func (c *Client) ServiceName() string

func (*Client) SetDialer

func (c *Client) SetDialer(dialer him.Dialer)

type ClientOptions

type ClientOptions struct {
	Heartbeat time.Duration
	ReadWait  time.Duration
	WriteWait time.Duration
}

type Frame

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

Frame Frame 帧处理 对ws.Frame包装, 实现了him.Frame接口

func (*Frame) GetOpCode

func (f *Frame) GetOpCode() him.OpCode

func (*Frame) GetPayload

func (f *Frame) GetPayload() []byte

func (*Frame) SetOpCode

func (f *Frame) SetOpCode(code him.OpCode)

func (*Frame) SetPayload

func (f *Frame) SetPayload(payload []byte)

type Server

type Server struct {
	him.ServiceRegistration
	him.ChannelMap
	him.Acceptor
	him.MessageListener
	him.StateListener
	// contains filtered or unexported fields
}

Server is a websocket implement of the Server interface

func (*Server) Push

func (s *Server) Push(id string, data []byte) error

func (*Server) SetAcceptor

func (s *Server) SetAcceptor(acceptor him.Acceptor)

func (*Server) SetChannelMap

func (s *Server) SetChannelMap(channelMap him.ChannelMap)

func (*Server) SetMessageListener

func (s *Server) SetMessageListener(listener him.MessageListener)

func (*Server) SetReadWait

func (s *Server) SetReadWait(readWait time.Duration)

func (*Server) SetStateListener

func (s *Server) SetStateListener(listener him.StateListener)

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

func (*Server) Start

func (s *Server) Start() error

type ServerOptions

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

type WsConn

type WsConn struct {
	net.Conn
}

WsConn 对net.Conn进行封装 解决websocket/tcp两种协议在 读/写 逻辑上的差异 依赖 Frame接口的实现

func NewConn

func NewConn(conn net.Conn) *WsConn

func (*WsConn) Flush

func (c *WsConn) Flush() error

func (*WsConn) ReadFrame

func (c *WsConn) ReadFrame() (him.Frame, error)

func (*WsConn) WriteFrame

func (c *WsConn) WriteFrame(code him.OpCode, payload []byte) error

Jump to

Keyboard shortcuts

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