An mqtt client in go supporting mqtt v3.1.1. Mostly for learning bit operations, not for production use.
- connect
- ping
- subscribe
- disconnect
- publish
- QoS
- session
- Composition over inheritance
- Simplicity: just packets and a stream
- Idiomatic go
- Decent test coverage
- Use
printf "%d\n" <hex>
andprintf "%x\n" <int>
to convert between integer and hex - Use
<-func()
to indicate waiting len(chan)
only shows unread items, not pending writersSIGINT
takes a while sinceDISCONNECT
is also time sharing the stream- Use
Set*Deadline
to cancelnet.Conn.Read
- Use
context
instead of closing a channel to abort reading a channel if you have multiple writers - Empty channels do not need to be closed. They will be garbage collected.
- Stopping a
time.Timer
does not closetime.Timer.C
so stopping a timer while we're reading from it in another goroutine will leave the channel open. Will this leak that goroutine? Or will gb reap it?
$ make test
$ make run
- use https://github.com/karlpokus/mqtt-parser for monitoring connection
- tests
- parse connack return codes
- verify pingresp after sending pingreq
- handle conn errors https://github.com/karlpokus/broker/blob/master/pkg/broker/broker.go
- try bytes.Buffer and buf.WriteTo(conn)
- close connection on disconnect
- rw wrapper that log op codes
- time share rw
- try buffered rwc - no
- stream.Fake
- rw error handling options: pass fatal or return err
- move opFuncs from packet to stream
- type op execution timeout
- implement read timeout for io.ReadWriter
- client ui
- client config
- client topic router
- prefix log records
- stop ops listener before exit
- pass error in Response
- ack pending queue
- maybe rename type op to tx
- good comments on packet bytes
- expose Response.Message and Topic
- *ack name in timeout error
- not before SUBACK popped should we notify client
- ack name
- reconnect option
- make op funcs cancelable
- generate packet id
- client initiated disconnect
- convert packet.Packet to func(b)