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)
| 1156 | // reader Read methods. The application must read the connection to process |
| 1157 | // ping messages as described in the section on Control Messages above. |
| 1158 | func (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 |
| 1174 | func (c *Conn) PongHandler() func(appData string) error { |
no test coverage detected