mqtt

package
v0.0.0-...-02d3639 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2016 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package mqtt implements MQTT clients and servers.

Index

Constants

This section is empty.

Variables

View Source
var ConnectionErrors = [6]error{
	nil,
	errors.New("Connection Refused: unacceptable protocol version"),
	errors.New("Connection Refused: identifier rejected"),
	errors.New("Connection Refused: server unavailable"),
	errors.New("Connection Refused: bad user name or password"),
	errors.New("Connection Refused: not authorized"),
}

ConnectionErrors is an array of errors corresponding to the Connect return codes specified in the specification.

Functions

This section is empty.

Types

type ClientConn

type ClientConn struct {
	ClientId string              // May be set before the call to Connect.
	Dump     bool                // When true, dump the messages in and out.
	Incoming chan *proto.Publish // Incoming messages arrive on this channel.
	// contains filtered or unexported fields
}

A ClientConn holds all the state associated with a connection to an MQTT server. It should be allocated via NewClientConn.

func NewClientConn

func NewClientConn(c net.Conn) *ClientConn

NewClientConn allocates a new ClientConn.

func (*ClientConn) Connect

func (c *ClientConn) Connect(user, pass string) error

Send the CONNECT message to the server. If the ClientId is not already set, use a default (a 63-bit decimal random number). The "clean session" bit is always set.

func (*ClientConn) Disconnect

func (c *ClientConn) Disconnect()

Sent a DISCONNECT message to the server. This function blocks until the disconnect message is actually sent, and the connection is closed.

func (*ClientConn) Publish

func (c *ClientConn) Publish(m *proto.Publish)

Publish publishes the given message to the MQTT server. The QosLevel of the message must be QosAtLeastOnce for now.

func (*ClientConn) Subscribe

func (c *ClientConn) Subscribe(tqs []proto.TopicQos) *proto.SubAck

Subscribe subscribes this connection to a list of topics. Messages will be delivered on the Incoming channel.

type Server

type Server struct {
	Done          chan struct{}
	StatsInterval time.Duration // Defaults to 10 seconds. Must be set using sync/atomic.StoreInt64().
	Dump          bool          // When true, dump the messages in and out.
	// contains filtered or unexported fields
}

A Server holds all the state associated with an MQTT server.

func NewServer

func NewServer(l net.Listener) *Server

NewServer creates a new MQTT server, which accepts connections from the given listener. When the server is stopped (for instance by another goroutine closing the net.Listener), channel Done will become readable.

func (*Server) Start

func (s *Server) Start()

Start makes the Server start accepting and handling connections.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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