Documentation
¶
Overview ¶
Package tt provides components for writing mqtt-v5 clients.
Example (Client) ¶
Example shows a simple client for connect, publish a QoS 0 and disconnect.
package main
import (
"context"
"sogvin.com/mq"
"sogvin.com/tt"
"sogvin.com/tt/event"
)
func main() {
client := tt.NewClient()
client.SetServer("tcp://localhost:1883")
ctx := context.Background()
go client.Run(ctx)
// v is either an packet or a event type
for v := range client.Events() {
switch v := v.(type) {
case event.ClientUp:
_ = client.Send(ctx, mq.NewConnect())
case event.ClientConnect:
// do something once you are connected
p := mq.Pub(0, "gopher/happy", "yes")
_ = client.Send(ctx, p)
case *mq.Publish:
_ = v // do something the received packet
case event.ClientStop:
// do some clean up maybe
}
}
}
Output:
Example (Server) ¶
Example shows how to run the provided server.
package main
import (
"context"
"log"
"sogvin.com/tt"
"sogvin.com/tt/event"
)
func main() {
srv := tt.NewServer()
ctx := context.Background()
go srv.Run(ctx)
for v := range srv.Events() {
switch v := v.(type) {
case event.ServerStop:
if v.Err != nil {
log.Println(v.Err)
}
}
}
}
Output:
Index ¶
- Constants
- Variables
- type Bind
- type Client
- func (c *Client) Events() <-chan interface{}
- func (c *Client) Run(ctx context.Context) error
- func (c *Client) Send(ctx context.Context, p mq.Packet) error
- func (c *Client) SetDebug(v bool)
- func (c *Client) SetLogger(v *log.Logger)
- func (c *Client) SetMaxPacketID(v uint16)
- func (c *Client) SetServer(v string)
- type Connection
- type Server
- func (s *Server) AddBind(b *Bind)
- func (s *Server) ConnectTimeout() time.Duration
- func (s *Server) Events() <-chan interface{}
- func (s *Server) Handle(ctx context.Context, conn Connection)
- func (s *Server) Incoming() chan<- Connection
- func (s *Server) Run(ctx context.Context)
- func (s *Server) SetConnectTimeout(v time.Duration)
- func (s *Server) SetDebug(v bool)
- func (s *Server) SetLogger(v *log.Logger)
Examples ¶
Constants ¶
const StatLine = "Revision ConnCount ConnActive NumGoroutine MemAlloc"
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Bind ¶
Bind holds server listening settings
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client implements a mqtt-v5 client.
func NewClient ¶
func NewClient() *Client
NewClient returns new client with no logging pointing to tcp://127.0.0.1:1883 wich max packet ID 10.
func (*Client) Events ¶
func (c *Client) Events() <-chan interface{}
Events returns a channel used by client to inform application layer of packets and events. E.g. event.ClientUp
func (*Client) Run ¶
Run the client, blocks until stopped or disconnected.
func (*Client) Send ¶
Send returns when the packet was successfully encoded on the wire. Returns ErrClientStopped if not running. Send is safe to call concurrently.
type Connection ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
func NewServer() *Server
NewServer returns a server ready to run. Configure any settings before calling Run.
func (*Server) AddBind ¶
AddBind which to listen on for connections, defaults to tcp://localhost:, ie. random port on localhost.
func (*Server) Events ¶
func (s *Server) Events() <-chan interface{}
Events returns a channel used by server to inform the application layer of events. E.g event.ServerStop
func (*Server) Handle ¶
func (s *Server) Handle(ctx context.Context, conn Connection)
func (*Server) Incoming ¶
func (s *Server) Incoming() chan<- Connection
Incoming returns channel on which to feed new connections
func (*Server) Run ¶
Run the server. Use Server.Events to listen for progress.
func (*Server) SetConnectTimeout ¶
Timeout for the initial connect packet from a client before disconnecting, default 200ms.
func (*Server) SetDebug ¶
SetDebug increases log information, default false.
Source Files
¶
- client.go
- match.go
- router.go
- serve.go
- server.go
- tt.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package arn provides an MQTT topic filter matcher.
|
Package arn provides an MQTT topic filter matcher. |
|
cmd
|
|
|
plot
command
|
|
|
tt
command
Command tt is a mqtt pub/sub client and broker
|
Command tt is a mqtt pub/sub client and broker |
|
Command feature documents tt features
|
Command feature documents tt features |
|
Package event provides client and server event types.
|
Package event provides client and server event types. |
|
Package spec implements implementation verifiers against the MQTTv5 specification
[4.7 Topic names and filters]: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901241
|
Package spec implements implementation verifiers against the MQTTv5 specification [4.7 Topic names and filters]: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901241 |
|
Package ttx provides test types
|
Package ttx provides test types |