move check for unresponsive clients to additional loops
This commit is contained in:
parent
15f6b0227a
commit
409fd741dd
1 changed files with 8 additions and 6 deletions
|
@ -22,17 +22,19 @@ func SendPermanentBroadCastMessage() {
|
||||||
|
|
||||||
// Iterate over all connected clients and broadcast the message
|
// Iterate over all connected clients and broadcast the message
|
||||||
for _, client := range Clients {
|
for _, client := range Clients {
|
||||||
if time.Now().Sub(client.LastPong) > 10*time.Second {
|
|
||||||
// Remove unresponsive client
|
|
||||||
client.Conn.Close()
|
|
||||||
delete(Clients, client.Conn.LocalAddr())
|
|
||||||
helper.Logger.Info("Client timed out", "host", client.RealIP, "clients", len(Clients))
|
|
||||||
}
|
|
||||||
err := client.SendMessage(websocket.TextMessage, jsonMessage)
|
err := client.SendMessage(websocket.TextMessage, jsonMessage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
helper.Logger.Info("Error broadcasting to client:", "msg", err, "host", client.RealIP, "clients", len(Clients))
|
helper.Logger.Info("Error broadcasting to client:", "msg", err, "host", client.RealIP, "clients", len(Clients))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for _, client := range Clients {
|
||||||
|
if time.Now().Sub(client.LastPong) > (10 * time.Second) {
|
||||||
|
// Remove unresponsive client
|
||||||
|
client.Conn.Close()
|
||||||
|
delete(Clients, client.Conn.LocalAddr())
|
||||||
|
helper.Logger.Info("Client timed out", "host", client.RealIP, "clients", len(Clients))
|
||||||
|
}
|
||||||
|
}
|
||||||
<-tick.C
|
<-tick.C
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue