MCPcopy
hub / github.com/gorilla/websocket / SetPingHandler

Method SetPingHandler

conn.go:1158–1171  ·  view source on GitHub ↗

SetPingHandler sets the handler for ping messages received from the peer. The appData argument to h is the PING message application data. The default ping handler sends a pong to the peer. The handler function is called from the NextReader, ReadMessage and message reader Read methods. The applicati

(h func(appData string) error)

Source from the content-addressed store, hash-verified

1156// reader Read methods. The application must read the connection to process
1157// ping messages as described in the section on Control Messages above.
1158func (c *Conn) SetPingHandler(h func(appData string) error) {
1159 if h == nil {
1160 h = func(message string) error {
1161 err := c.WriteControl(PongMessage, []byte(message), time.Now().Add(writeWait))
1162 if err == ErrCloseSent {
1163 return nil
1164 } else if e, ok := err.(net.Error); ok && e.Temporary() {
1165 return nil
1166 }
1167 return err
1168 }
1169 }
1170 c.handlePing = h
1171}
1172
1173// PongHandler returns the current pong handler
1174func (c *Conn) PongHandler() func(appData string) error {

Callers 1

newConnFunction · 0.95

Calls 2

WriteControlMethod · 0.95
TemporaryMethod · 0.80

Tested by

no test coverage detected