1 Star 1 Fork 0

低调的一鸣哥/mqtt

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
main.go 828 Bytes
Copy Edit Raw Blame History
Jeff R. Allen authored 2013-12-05 23:47 +08:00 . go fmt
package main
import (
"crypto/tls"
"github.com/jeffallen/mqtt"
"log"
)
// See http://mosquitto.org/man/mosquitto-tls-7.html for how to make the
// server.{crt,key} files. Then use mosquitto like this to talk to it:
//
// mosquitto_sub --cafile ca.crt --tls-version tlsv1 -p 8883
//
// tls-version is required, because Go's TLS is limited to TLS 1.0, but
// OpenSSL will try to ask for TLS 1.2 by default.
func readCert() []tls.Certificate {
c, err := tls.LoadX509KeyPair("server.crt", "server.key")
if err != nil {
panic(err)
}
return []tls.Certificate{c}
}
func main() {
cfg := &tls.Config{
Certificates: readCert(),
NextProtos: []string{"mqtt"},
}
l, err := tls.Listen("tcp", ":8883", cfg)
if err != nil {
log.Print("listen: ", err)
return
}
svr := mqtt.NewServer(l)
svr.Start()
<-svr.Done
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mingyiyi72/mqtt.git
git@gitee.com:mingyiyi72/mqtt.git
mingyiyi72
mqtt
mqtt
6e47de95450e

Search