client

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusInitial = iota
	StatusConnecting
	StatusConnected
	StatusClosed
)

Variables

View Source
var (
	ErrInvalidStatus = errors.New("invalid client status")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	*Options
	session.BaseSession
	// contains filtered or unexported fields
}

func NewClient

func NewClient(codec message.Codec, listener session.Listener, opts ...Option) (*Client, error)

func (*Client) Close

func (client *Client) Close() error

func (*Client) CloseWithContext

func (client *Client) CloseWithContext(ctx context.Context) error

func (*Client) Connection

func (client *Client) Connection() session.Conn

func (*Client) Dial

func (client *Client) Dial(ctx context.Context, address string) error

Dial

@Description: 连接
@receiver client
@param ctx
@param address 如:127.0.0.1:9999
@return error

func (*Client) IsClosed

func (client *Client) IsClosed() bool

func (*Client) SendMessage

func (client *Client) SendMessage(message any)

SendMessage

@Description: 发送消息
@receiver client
@param message

func (*Client) SendMessages

func (client *Client) SendMessages(messages ...any)

SendMessages

@Description: 发送多条消息
@receiver client
@param messages

func (*Client) Status

func (client *Client) Status() uint32

type Conn

type Conn struct {
	*websocket.Conn
	session.BaseConn
	// contains filtered or unexported fields
}

func NewConn

func NewConn(client *Client, pConn *websocket.Conn) (*Conn, error)

func (*Conn) AsyncWrite

func (conn *Conn) AsyncWrite(buf []byte, callback func(c session.Conn, err error) error) (err error)

func (*Conn) AsyncWritev

func (conn *Conn) AsyncWritev(bs [][]byte, callback func(c session.Conn, err error) error) (err error)

func (*Conn) Context

func (conn *Conn) Context() (ctx any)

func (*Conn) Discard

func (conn *Conn) Discard(n int) (discarded int, err error)

func (*Conn) Flush

func (conn *Conn) Flush() (err error)

func (*Conn) InboundBuffered

func (conn *Conn) InboundBuffered() (n int)

func (*Conn) Init

func (conn *Conn) Init(client *Client, pConn *websocket.Conn) error

func (*Conn) Next

func (conn *Conn) Next(n int) (buf []byte, err error)

func (*Conn) OutboundBuffered

func (conn *Conn) OutboundBuffered() (n int)

func (*Conn) Peek

func (conn *Conn) Peek(n int) (buf []byte, err error)

func (*Conn) Read

func (conn *Conn) Read(_ []byte) (n int, err error)

func (*Conn) ReadFrom

func (conn *Conn) ReadFrom(r io.Reader) (n int64, err error)

func (*Conn) SetContext

func (conn *Conn) SetContext(ctx any)

func (*Conn) SetDeadline

func (conn *Conn) SetDeadline(t time.Time) error

func (*Conn) Write

func (conn *Conn) Write(_ []byte) (n int, err error)

func (*Conn) WriteTo

func (conn *Conn) WriteTo(w io.Writer) (n int64, err error)

func (*Conn) Writev

func (conn *Conn) Writev(bs [][]byte) (n int, err error)

type Option

type Option func(*Options)

func WithMaxMessageLength

func WithMaxMessageLength(value int64) Option

func WithName

func WithName(value string) Option

func WithWriteQueueCap

func WithWriteQueueCap(cap int) Option

type Options

type Options struct {
	Name string
	// 同时提交写队列上限,队列满时异步写直接返回错误
	WriteQueueCap int
	// 最大消息长度
	MaxMessageLength int64
}

Jump to

Keyboard shortcuts

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