forked from jshiffer/go-xmpp
Add Client Manager to monitor connection state and trigger reconnect (#39)
- Support for exponential backoff on reconnect to be gentle on the server. - Clean up client by moving metrics and retry strategy to the connection manager. - Update echo_client to use client manager - Fix echo client XMPP message matching Fixes #21 Improvements for #8
This commit is contained in:
@@ -26,17 +26,14 @@ func main() {
|
||||
log.Fatal("Error: ", err)
|
||||
}
|
||||
|
||||
session, err := client.Connect()
|
||||
if err != nil {
|
||||
log.Fatal("Error: ", err)
|
||||
}
|
||||
|
||||
fmt.Println("Stream opened, we have streamID = ", session.StreamId)
|
||||
cm := xmpp.NewClientManager(client, nil)
|
||||
cm.Start()
|
||||
// connection can be stopped with cm.Stop().
|
||||
|
||||
// Iterator to receive packets coming from our XMPP connection
|
||||
for packet := range client.Recv() {
|
||||
switch packet := packet.(type) {
|
||||
case *xmpp.Message:
|
||||
case xmpp.Message:
|
||||
_, _ = fmt.Fprintf(os.Stdout, "Body = %s - from = %s\n", packet.Body, packet.From)
|
||||
reply := xmpp.Message{PacketAttrs: xmpp.PacketAttrs{To: packet.From}, Body: packet.Body}
|
||||
_ = client.Send(reply)
|
||||
@@ -47,6 +44,4 @@ func main() {
|
||||
}
|
||||
|
||||
// TODO create default command line client to send message or to send an arbitrary XMPP sequence from a file,
|
||||
// (using templates ?)
|
||||
|
||||
// TODO: autoreconnect when connection is lost
|
||||
// (using templates ?)
|
||||
|
||||
@@ -101,8 +101,7 @@ func playSCURL(p *mpg123.Player, rawURL string) {
|
||||
|
||||
func connectXmpp(jid string, password string, address string) (client *xmpp.Client, err error) {
|
||||
xmppConfig := xmpp.Config{Address: address,
|
||||
Jid: jid, Password: password, PacketLogger: os.Stdout, Insecure: true,
|
||||
Retry: 10}
|
||||
Jid: jid, Password: password, PacketLogger: os.Stdout, Insecure: true}
|
||||
|
||||
if client, err = xmpp.NewClient(xmppConfig); err != nil {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user