|
|
@ -3,6 +3,7 @@ package core_client |
|
|
|
import ( |
|
|
|
"net/http" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
|
|
|
|
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/gorilla/websocket" |
|
|
|
. "github.com/tendermint/tendermint/common" |
|
|
@ -12,8 +13,11 @@ import ( |
|
|
|
"github.com/tendermint/tendermint/wire" |
|
|
|
) |
|
|
|
|
|
|
|
const wsEventsChannelCapacity = 10 |
|
|
|
const wsResultsChannelCapacity = 10 |
|
|
|
const ( |
|
|
|
wsEventsChannelCapacity = 10 |
|
|
|
wsResultsChannelCapacity = 10 |
|
|
|
wsWriteTimeoutSeconds = 10 |
|
|
|
) |
|
|
|
|
|
|
|
type WSClient struct { |
|
|
|
QuitService |
|
|
@ -53,6 +57,14 @@ func (wsc *WSClient) dial() error { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
// Set the ping/pong handlers
|
|
|
|
con.SetPingHandler(func(m string) error { |
|
|
|
con.WriteControl(websocket.PongMessage, []byte(m), time.Now().Add(time.Second*wsWriteTimeoutSeconds)) |
|
|
|
return nil |
|
|
|
}) |
|
|
|
con.SetPongHandler(func(m string) error { |
|
|
|
return nil |
|
|
|
}) |
|
|
|
wsc.Conn = con |
|
|
|
return nil |
|
|
|
} |
|
|
@ -65,14 +77,14 @@ func (wsc *WSClient) receiveEventsRoutine() { |
|
|
|
for { |
|
|
|
_, data, err := wsc.ReadMessage() |
|
|
|
if err != nil { |
|
|
|
log.Info(Fmt("WSClient failed to read message: %v", err)) |
|
|
|
log.Info("WSClient failed to read message", "error", err, "data", string(data)) |
|
|
|
wsc.Stop() |
|
|
|
break |
|
|
|
} else { |
|
|
|
var response ctypes.Response |
|
|
|
wire.ReadJSON(&response, data, &err) |
|
|
|
if err != nil { |
|
|
|
log.Info(Fmt("WSClient failed to parse message: %v", err)) |
|
|
|
log.Info("WSClient failed to parse message", "error", err) |
|
|
|
wsc.Stop() |
|
|
|
break |
|
|
|
} |
|
|
|