Documentation
¶
Index ¶
- type ActionFn
- type Client
- func (p *Client) AddAction(actionFn ActionFn)
- func (p *Client) ConnectToTCP(addr string, tlsConfig ...*tls.Config) error
- func (p *Client) ConnectToWS(addr string, path string, tlsConfig ...*tls.Config) error
- func (p *Client) Disconnect()
- func (p *Client) HandshakeData() *HandshakeData
- func (p *Client) IsConnected() bool
- func (p *Client) Notify(route string, val interface{}) error
- func (p *Client) On(route string, fn OnMessageFn)
- func (p *Client) Request(route string, val interface{}) (*pomeloMessage.Message, error)
- func (p *Client) Send(msgType pomeloMessage.Type, route string, val interface{}) (uint, error)
- func (p *Client) SendRaw(typ pomeloPacket.Type, data []byte) error
- func (p *Client) Serializer() cfacade.ISerializer
- type HandshakeData
- type HandshakeSys
- type OnMessageFn
- type Option
- type RequestContext
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 ¶
New returns a new pomelo client with default options. Use With* Option functions to customize the client before connecting.
func (*Client) ConnectToTCP ¶
ConnectToTCP establishes a TCP connection to the given address, performs the pomelo handshake, and starts the read/write loops.
func (*Client) ConnectToWS ¶
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 ¶
IsConnected returns whether the client is currently connected.
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 ¶
Send encodes and enqueues a message for writing to the server. Returns the auto-incremented message id.
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 ¶
WithErrorBreak sets whether the client disconnects when an action returns an error.
func WithHandshake ¶
WithHandshake sets the handshake payload sent to the server.
func WithHeartbeat ¶
WithHeartbeat sets the heartbeat interval in seconds.
func WithRequestTimeout ¶
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 ¶
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.