package main
import (
"os"
"log"
"github.com/eclipse/paho.mqtt.golang"
)
func main() {
mqtt.DEBUG = log.New(os.Stdout, "", 0) mqtt.ERROR = log.New(os.Stdout, "", 0) opts := mqtt.NewClientOptions().AddBroker("tcp://dev.corp.wingoht.com:1883").SetClientID("mqtt_client") c := mqtt.NewClient(opts) if token := c.Connect(); token.Wait() && token.Error() != nil { panic(token.Error()) } token := c.Publish(receiver, 0, false, content) token.Wait() c.Disconnect(250)
}
首先要下载"github.com/eclipse/paho.mqtt.golang"以及”golang.org\x\net“