union

package
v0.0.0-...-3c4aecd Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2021 License: MulanPSL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn interface {
	// WriteMessage writes data to the connection.
	WriteMessage(mt ControlType, data []byte) error

	// ReadMessage reads data from the connection.
	ReadMessage(mt ControlType) ([]byte, error)

	// Close closes the connection.
	// Any blocked Read or Write operations will be unblocked and return errors.
	Close() error

	// LocalAddr returns the local network address.
	LocalAddr() net.Addr

	// RemoteAddr returns the remote network address.
	RemoteAddr() net.Addr

	// SetReadDeadline sets the deadline for future Read calls
	// and any currently-blocked Read call.
	// A zero value for t means Read will not time out.
	SetReadDeadline(t time.Time) error

	// SetWriteDeadline sets the deadline for future Write calls
	// and any currently-blocked Write call.
	// Even if write times out, it may return n > 0, indicating that
	// some of the data was successfully written.
	// A zero value for t means Write will not time out.
	SetWriteDeadline(t time.Time) error
}

Conn 统一的连接操作

type ControlType

type ControlType int

ControlType 控制类型

const (
	// TextMessage 文本消息
	TextMessage ControlType = 1
	// BinaryMessage 二进制消息
	BinaryMessage ControlType = 2
)

func (ControlType) String

func (ct ControlType) String() string

type NetConn

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

NetConn golang默认连接

func NewNetConn

func NewNetConn(conn net.Conn, msgLenBytes, maxMsgLen int) *NetConn

func (*NetConn) Close

func (nc *NetConn) Close() error

func (*NetConn) LocalAddr

func (nc *NetConn) LocalAddr() net.Addr

func (*NetConn) ReadMessage

func (nc *NetConn) ReadMessage(mt ControlType) ([]byte, error)

func (*NetConn) RemoteAddr

func (nc *NetConn) RemoteAddr() net.Addr

func (*NetConn) SetReadDeadline

func (nc *NetConn) SetReadDeadline(t time.Time) error

func (*NetConn) SetWriteDeadline

func (nc *NetConn) SetWriteDeadline(t time.Time) error

func (*NetConn) WriteMessage

func (nc *NetConn) WriteMessage(mt ControlType, data []byte) error

type WSConn

type WSConn struct {
	sync.Mutex
	// contains filtered or unexported fields
}

WSConn gorilla websocket连接

func NewWSConn

func NewWSConn(conn *websocket.Conn, ip string) *WSConn

func (*WSConn) Close

func (wsc *WSConn) Close() error

func (*WSConn) LocalAddr

func (wsc *WSConn) LocalAddr() net.Addr

func (*WSConn) ReadMessage

func (wsc *WSConn) ReadMessage(ct ControlType) ([]byte, error)

func (*WSConn) RemoteAddr

func (wsc *WSConn) RemoteAddr() net.Addr

func (*WSConn) SetReadDeadline

func (wsc *WSConn) SetReadDeadline(t time.Time) error

func (*WSConn) SetWriteDeadline

func (wsc *WSConn) SetWriteDeadline(t time.Time) error

func (*WSConn) WriteMessage

func (wsc *WSConn) WriteMessage(ct ControlType, data []byte) error

Jump to

Keyboard shortcuts

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