Added multiple client connections in go rutines

This commit is contained in:
2021-09-16 10:18:44 +02:00
parent 9095638867
commit 1d2a8068dd
2 changed files with 69 additions and 38 deletions

26
main.go
View File

@@ -1,6 +1,9 @@
package main
import (
"log"
"time"
appConfig "github.com/xmpploadtesting/config"
xmppService "github.com/xmpploadtesting/services"
)
@@ -15,5 +18,26 @@ func main() {
// Send online presence stanza
xmppServiceInstance := xmppService.Instance()
xmppService.SendOnlinePresenceStanza(xmppServiceInstance.XMPPClients[0].Client, xmppServiceInstance.XMPPClients[0].Config.Jid)
for {
for _, xmppClient := range xmppServiceInstance.XMPPClients {
// Send online presence stanza in go rutines
go func(xmppClient xmppService.XMPPClient) {
log.Printf("online presence stanza FOR %v", xmppClient.Config.Jid)
err := xmppService.SendOnlinePresenceStanza(xmppClient.Client, xmppClient.Config.Jid)
if err != nil {
log.Printf("There was an error while sending online presence stanza %v", err)
}
}(xmppClient)
}
// Delay before sending another message
time.Sleep(time.Duration(appConfig.AppConfig.GeneralOptions.DelayBetweenMassages))
}
}