Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
windycrypto committed Nov 27, 2023
1 parent c59f768 commit eed14b4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
31 changes: 15 additions & 16 deletions relay/wsconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"strings"
"sync/atomic"
"time"

"github.com/RabbyHub/derelay/log"
"github.com/RabbyHub/derelay/metrics"
Expand Down Expand Up @@ -42,24 +41,24 @@ func (c *client) MarshalLogObject(encoder zapcore.ObjectEncoder) error {
return nil
}

func (c *client) heartbeat() {
// func (c *client) heartbeat() {

c.conn.SetPongHandler(func(appData string) error {
c.active = true
return nil
})
// c.conn.SetPongHandler(func(appData string) error {
// c.active = true
// return nil
// })

for {
if !c.active {
c.terminate(fmt.Errorf("heartbeat fail"))
return
}
c.active = false
// for {
// if !c.active {
// c.terminate(fmt.Errorf("heartbeat fail"))
// return
// }
// c.active = false

_ = c.conn.WriteControl(websocket.PingMessage, []byte("ping"), time.Now().Add(5*time.Second))
<-time.After(10 * time.Second)
}
}
// _ = c.conn.WriteControl(websocket.PingMessage, []byte("ping"), time.Now().Add(5*time.Second))
// <-time.After(10 * time.Second)
// }
// }

func (c *client) read() {
for {
Expand Down
2 changes: 1 addition & 1 deletion relay/wsserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (ws *WsServer) NewClientConn(w http.ResponseWriter, r *http.Request) {

go client.read()
go client.write()
go client.heartbeat()
//go client.heartbeat()
}

func (ws *WsServer) Run() {
Expand Down

0 comments on commit eed14b4

Please sign in to comment.