go-xmpp/cmd/xmpp_component/xmpp_component.go

29 lines
475 B
Go
Raw Normal View History

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