go-xmpp/cmd/xmpp_component/xmpp_component.go

31 lines
503 B
Go
Raw Normal View History

2018-01-11 21:15:54 +00:00
package main
2018-01-12 18:08:47 +00:00
import (
"fmt"
"fluux.io/xmpp"
)
2018-01-11 21:15:54 +00:00
func main() {
2018-01-12 17:14:41 +00:00
component := xmpp.Component{Host: "mqtt.localhost", Secret: "mypass"}
component.Connect("localhost:8888")
2018-01-12 18:08:47 +00:00
for {
2018-01-13 17:50:17 +00:00
packet, err := component.ReadPacket()
2018-01-12 18:08:47 +00:00
if err != nil {
2018-01-13 16:46:10 +00:00
fmt.Println("read error", err)
2018-01-12 18:08:47 +00:00
return
}
2018-01-13 17:50:17 +00:00
switch p := packet.(type) {
case xmpp.IQ:
2018-01-13 18:14:26 +00:00
switch p.Payload.(type) {
case *xmpp.Query:
fmt.Println("Received query:", p.Type)
}
2018-01-13 17:50:17 +00:00
default:
fmt.Println("Packet unhandled packet:", packet)
}
2018-01-12 18:08:47 +00:00
}
2018-01-11 21:15:54 +00:00
}