Documentation
¶
Index ¶
- type Client
- func (client *Client) Alive() bool
- func (client *Client) Connect() (err error)
- func (client *Client) Connected() bool
- func (client *Client) Disconnect()
- func (client *Client) Init() (err error)
- func (client *Client) Publish(topic string, qos byte, retain bool, payload interface{}) (err error)
- func (client *Client) Subscribe(topic string, qos byte) (err error)
- func (client *Client) Unsubscribe(topic string)
- type Receiver
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { Broker string // Broker URL to connect User string // Broker User name for authentication Password string // Broker password for authentication ClientId string // Client ID CleanSession bool // Clear session at Broker on connect, default false Qos int // Quality of Service, (i.e, 0: QOS0, 1 QOS1, 2 QOS2) DisconnectInterval uint // Client will disconnect after wait of this period, default 0 MessageArrived Receiver // Subscribe receiver handler for this client object // contains filtered or unexported fields }
Client struct contains MQTT client configuration and handle of client connection for further access of publish and subscriptions. There is not any restriction on number of client instances. User can define multiple instances for same broker or different brokers in single application.
func (*Client) Alive ¶
Alive returns true if client is connected to broker. It returns true even if client is in reconnecting state.
This can be used to check whether client is connected to broker or not regardless of various MQTT connection stages.
func (*Client) Connect ¶
Connect initiates MQTT Connect sequence as per MQTT protocol. On receiving CONN ACK from broker, it changes state to connected. On failure returns error.
func (*Client) Connected ¶
Connected returns true if client is connected to broker actively. It returns false if client is in reconnect or disconnected mode
This can be used to get absolute connection state to broker.
func (*Client) Disconnect ¶
func (client *Client) Disconnect()
Disconnect drops connection to MQTT broker.
func (*Client) Init ¶
Init is an initialization function for defined Client object. Each client object has Init function which must be called before accessing any other member functions of struct Client.
func (*Client) Subscribe ¶
Subscribe performs subscription on MQTT broker for specific topic with QOS Client library will call message handler on reception of any message on subscribed topic.
func (*Client) Unsubscribe ¶
Unsubscribe is used to remove subscription of specific topic from MQTT broker. After this operation, client will not receive any message published on unsubscribed topic.