try to check for last ping connect
This commit is contained in:
parent
201e5779e6
commit
15f6b0227a
2 changed files with 7 additions and 7 deletions
|
@ -22,11 +22,14 @@ func SendPermanentBroadCastMessage() {
|
|||
|
||||
// Iterate over all connected clients and broadcast the message
|
||||
for _, client := range Clients {
|
||||
err := client.SendMessage(websocket.TextMessage, jsonMessage)
|
||||
if err != nil {
|
||||
// Remove client on error
|
||||
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)
|
||||
if err != nil {
|
||||
helper.Logger.Info("Error broadcasting to client:", "msg", err, "host", client.RealIP, "clients", len(Clients))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,10 +30,7 @@ func (c *WebsocketClient) SendMessage(messageType int, data []byte) error {
|
|||
return nil
|
||||
})
|
||||
c.Conn.SetWriteDeadline(time.Now().Add(TIMEOUT * time.Second))
|
||||
err := c.Conn.WriteMessage(websocket.PingMessage, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.Conn.WriteMessage(websocket.PingMessage, nil)
|
||||
|
||||
c.Conn.SetWriteDeadline(time.Now().Add(TIMEOUT * time.Second))
|
||||
return c.Conn.WriteMessage(messageType, data)
|
||||
|
|
Loading…
Reference in a new issue