Documentation ¶
Overview ¶
Package client provides an MQTT Client.
Index ¶
- Variables
- type Client
- func (cli *Client) Connect(opts *ConnectOptions) error
- func (cli *Client) Disconnect() error
- func (cli *Client) Publish(opts *PublishOptions) error
- func (cli *Client) Subscribe(opts *SubscribeOptions) error
- func (cli *Client) Terminate()
- func (cli *Client) Unsubscribe(opts *UnsubscribeOptions) error
- type ConnectOptions
- type ErrorHandler
- type MessageHandler
- type Options
- type PublishOptions
- type SubReq
- type SubscribeOptions
- type UnsubscribeOptions
Constants ¶
This section is empty.
Variables ¶
var ( ErrAlreadyConnected = errors.New("the Client has already connected to the Server") ErrNotYetConnected = errors.New("the Client has not yet connected to the Server") ErrCONNACKTimeout = errors.New("the CONNACK Packet was not received within a reasonalbe amount of time") ErrPINGRESPTimeout = errors.New("the PINGRESP Packet was not received within a reasonalbe amount of time") ErrPacketIDExhaused = errors.New("Packet Identifiers are exhausted") ErrInvalidPINGRESP = errors.New("invalid PINGRESP Packet") ErrInvalidSUBACK = errors.New("invalid SUBACK Packet") )
Error values
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a Client.
func (*Client) Connect ¶
func (cli *Client) Connect(opts *ConnectOptions) error
Connect establishes a Network Connection to the Server and sends a CONNECT Packet to the Server.
func (*Client) Disconnect ¶
Disconnect sends a DISCONNECT Packet to the Server and closes the Network Connection.
func (*Client) Publish ¶
func (cli *Client) Publish(opts *PublishOptions) error
Publish sends a PUBLISH Packet to the Server.
func (*Client) Subscribe ¶
func (cli *Client) Subscribe(opts *SubscribeOptions) error
Subscribe sends a SUBSCRIBE Packet to the Server.
func (*Client) Unsubscribe ¶
func (cli *Client) Unsubscribe(opts *UnsubscribeOptions) error
Unsubscribe sends an UNSUBSCRIBE Packet to the Server.
type ConnectOptions ¶
type ConnectOptions struct { // Network is the network on which the Client connects to. Network string // Address is the address which the Client connects to. Address string // TLSConfig is the configuration for the TLS connection. TLSConfig *tls.Config // CONNACKTimeout is timeout in seconds for the Client // to wait for receiving the CONNACK Packet after sending // the CONNECT Packet. DailTimeout time.Duration CONNACKTimeout time.Duration // PINGRESPTimeout is timeout in seconds for the Client // to wait for receiving the PINGRESP Packet after sending // the PINGREQ Packet. PINGRESPTimeout time.Duration // ClientID is the Client Identifier of the payload. ClientID []byte // UserName is the User Name of the payload. UserName []byte // Password is the Password of the payload. Password []byte // CleanSession is the Clean Session of the variable header. CleanSession bool // KeepAlive is the Keep Alive of the variable header. KeepAlive uint16 // WillTopic is the Will Topic of the payload. WillTopic []byte // WillMessage is the Will Message of the payload. WillMessage []byte // WillQoS is the Will QoS of the variable header. WillQoS byte // WillRetain is the Will Retain of the variable header. WillRetain bool }
ConnectOptions represents options for the Connect method of the Client.
type ErrorHandler ¶
type ErrorHandler func(error)
ErrorHandler is the handler which handles an error.
type MessageHandler ¶
type MessageHandler func(topicName, message []byte)
MessageHandler is the handler which handles the Application Message sent from the Server.
type Options ¶
type Options struct { // ErrorHandler is the error handler. ErrorHandler ErrorHandler }
Options represents options for the Client.
type PublishOptions ¶
type PublishOptions struct { // QoS is the QoS of the fixed header. QoS byte // Retain is the Retain of the fixed header. Retain bool // TopicName is the Topic Name of the varible header. TopicName []byte // Message is the Application Message of the payload. Message []byte }
PublishOptions represents options for the Publish method of the Client.
type SubReq ¶
type SubReq struct { // TopicFilter is the Topic Filter of the Subscription. TopicFilter []byte // QoS is the requsting QoS. QoS byte // Handler is the handler which handles the Application Message // sent from the Server. Handler MessageHandler }
SubReq represents subscription request.
type SubscribeOptions ¶
type SubscribeOptions struct { // SubReqs is a slice of the subscription requests. SubReqs []*SubReq }
SubscribeOptions represents options for the Subscribe method of the Client.
type UnsubscribeOptions ¶
type UnsubscribeOptions struct { // TopicFilters represents a slice of the Topic Filters. TopicFilters [][]byte }
UnsubscribeOptions represents options for the Unsubscribe method of the Client.