improve websocket ping and remodel for rename datapoint
This commit is contained in:
@@ -17,10 +17,10 @@ var Broadcast Clients = make(Clients)
|
||||
|
||||
const (
|
||||
// Time allowed to write a message to the peer.
|
||||
writeWait = 10 * time.Second
|
||||
writeWait = 30 * time.Second
|
||||
|
||||
// Time allowed to read the next pong message from the peer.
|
||||
pongWait = 10 * time.Second
|
||||
pongWait = 30 * time.Second
|
||||
|
||||
// Send pings to peer with this period. Must be less than pongWait.
|
||||
pingPeriod = (pongWait * 9) / 10
|
||||
@@ -34,6 +34,7 @@ type Client struct {
|
||||
OnMessage func(data []byte)
|
||||
OnClose func(code int, reason string)
|
||||
OnError func(err error)
|
||||
OnWarning func(warn string)
|
||||
OnPing func()
|
||||
OnPong func()
|
||||
send chan []byte
|
||||
@@ -177,7 +178,15 @@ func (c *Client) SendResponse(data []byte) {
|
||||
if !c.Connected {
|
||||
return
|
||||
}
|
||||
c.send <- data
|
||||
select {
|
||||
case c.send <- data:
|
||||
// sent successfully
|
||||
default:
|
||||
// channel full, drop or log
|
||||
if c.OnWarning != nil {
|
||||
c.OnWarning("Dropping message: channel full")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) Close(code int, reason string) error {
|
||||
|
Reference in New Issue
Block a user