CloseWithBytes cleanly closes the underlying WebSocket connection by sending given slice of bytes as a close message and then waiting (with timeout) for the server to close the connection. WebSocket close code may be optionally specified. If not, then "1000 - Normal Closure" will be used. WebSocke
(b []byte, code ...int)
| 287 | // conn := resp.Connection() |
| 288 | // conn.CloseWithBytes([]byte("bye!"), websocket.CloseGoingAway) |
| 289 | func (ws *Websocket) CloseWithBytes(b []byte, code ...int) *Websocket { |
| 290 | opChain := ws.chain.enter("CloseWithBytes()") |
| 291 | defer opChain.leave() |
| 292 | |
| 293 | switch { |
| 294 | case ws.checkUnusable(opChain, "CloseWithBytes()"): |
| 295 | return ws |
| 296 | |
| 297 | case len(code) > 1: |
| 298 | opChain.fail(AssertionFailure{ |
| 299 | Type: AssertUsage, |
| 300 | Errors: []error{ |
| 301 | errors.New("unexpected multiple code arguments"), |
| 302 | }, |
| 303 | }) |
| 304 | return ws |
| 305 | } |
| 306 | |
| 307 | ws.writeMessage(opChain, websocket.CloseMessage, b, code...) |
| 308 | |
| 309 | return ws |
| 310 | } |
| 311 | |
| 312 | // CloseWithJSON cleanly closes the underlying WebSocket connection |
| 313 | // by sending given object (marshaled using json.Marshal()) as a close message |