pomeloClient

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2026 License: MIT Imports: 18 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionFn

type ActionFn func() error

ActionFn is a deferred function executed in the client's event loop.

type Client

type Client struct {
	TagName string // 客户标识
	// contains filtered or unexported fields
}

Client struct

func New

func New(opts ...Option) *Client

New returns a new pomelo client with default options. Use With* Option functions to customize the client before connecting.

func (*Client) AddAction

func (p *Client) AddAction(actionFn ActionFn)

AddAction enqueues a function to be executed in the client's event loop.

func (*Client) ConnectToTCP

func (p *Client) ConnectToTCP(addr string, tlsConfig ...*tls.Config) error

ConnectToTCP establishes a TCP connection to the given address, performs the pomelo handshake, and starts the read/write loops.

func (*Client) ConnectToWS

func (p *Client) ConnectToWS(addr string, path string, tlsConfig ...*tls.Config) error

ConnectToWS establishes a WebSocket connection to the given address and path, performs the pomelo handshake, and starts the read/write loops.

func (*Client) Disconnect

func (p *Client) Disconnect()

Disconnect closes the connection and signals all goroutines to exit. Safe to call multiple times.

func (*Client) HandshakeData

func (p *Client) HandshakeData() *HandshakeData

HandshakeData returns the handshake data received from the server.

func (*Client) IsConnected

func (p *Client) IsConnected() bool

IsConnected returns whether the client is currently connected.

func (*Client) Notify

func (p *Client) Notify(route string, val interface{}) error

Notify sends a one-way notify message to the server.

func (*Client) On

func (p *Client) On(route string, fn OnMessageFn)

On registers a callback for push messages arriving on the given route.

func (*Client) Request

func (p *Client) Request(route string, val interface{}) (*pomeloMessage.Message, error)

Request sends a request to the server and blocks until a response is received or the request timeout is reached.

func (*Client) Send

func (p *Client) Send(msgType pomeloMessage.Type, route string, val interface{}) (uint, error)

Send encodes and enqueues a message for writing to the server. Returns the auto-incremented message id.

func (*Client) SendRaw

func (p *Client) SendRaw(typ pomeloPacket.Type, data []byte) error

func (*Client) Serializer

func (p *Client) Serializer() cfacade.ISerializer

Serializer returns the configured serializer.

type HandshakeData

type HandshakeData struct {
	Code int          `json:"code"`
	Sys  HandshakeSys `json:"sys"`
}

HandshakeData is the complete handshake response from the server. HandshakeData struct

type HandshakeSys

type HandshakeSys struct {
	Dict       map[string]uint16 `json:"dict"`
	Heartbeat  int               `json:"heartbeat"`
	Serializer string            `json:"serializer"`
}

HandshakeSys is the system data sent by the server during handshake.

type OnMessageFn

type OnMessageFn func(msg *pomeloMessage.Message)

OnMessageFn is called when a push message arrives on a bound route.

type Option

type Option func(options *options)

Option is a functional option for configuring a Client.

func WithErrorBreak

func WithErrorBreak(isBreak bool) Option

WithErrorBreak sets whether the client disconnects when an action returns an error.

func WithHandshake

func WithHandshake(handshake string) Option

WithHandshake sets the handshake payload sent to the server.

func WithHeartbeat

func WithHeartbeat(heartBeat int) Option

WithHeartbeat sets the heartbeat interval in seconds.

func WithRequestTimeout

func WithRequestTimeout(requestTimeout time.Duration) Option

WithRequestTimeout sets the timeout for request-response calls.

func WithSerializer

func WithSerializer(serializer cfacade.ISerializer) Option

WithSerializer sets the protocol serializer for the client.

type RequestContext

type RequestContext struct {
	*time.Ticker
	Chan chan *cmsg.Message
}

RequestContext carries the timeout ticker and response channel for a pending request.

func NewRequestContext

func NewRequestContext(t time.Duration) RequestContext

NewRequestContext creates a RequestContext with a ticker for the given timeout duration.

func (*RequestContext) Close

func (p *RequestContext) Close()

Close closes the response channel and stops the ticker.

Jump to

Keyboard shortcuts

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