CloseWithText cleanly closes the underlying WebSocket connection by sending given text 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. WebSocket close cod
(s string, code ...int)
| 385 | // conn := resp.Connection() |
| 386 | // conn.CloseWithText("bye!") |
| 387 | func (ws *Websocket) CloseWithText(s string, code ...int) *Websocket { |
| 388 | opChain := ws.chain.enter("CloseWithText()") |
| 389 | defer opChain.leave() |
| 390 | |
| 391 | switch { |
| 392 | case ws.checkUnusable(opChain, "CloseWithText()"): |
| 393 | return ws |
| 394 | |
| 395 | case len(code) > 1: |
| 396 | opChain.fail(AssertionFailure{ |
| 397 | Type: AssertUsage, |
| 398 | Errors: []error{ |
| 399 | errors.New("unexpected multiple code arguments"), |
| 400 | }, |
| 401 | }) |
| 402 | return ws |
| 403 | } |
| 404 | |
| 405 | ws.writeMessage(opChain, websocket.CloseMessage, []byte(s), code...) |
| 406 | |
| 407 | return ws |
| 408 | } |
| 409 | |
| 410 | // WriteMessage writes to the underlying WebSocket connection a message |
| 411 | // of given type with given content. |