close method
Closes a WebSocket connection.
Syntax
object.close(code, reason)Parameters
- code [in, optional]
-
Type: Number
- reason [in, optional]
-
Type: DOMString
Return value
This method does not return a value.
Remarks
When a WebSocket is closed, the onclose event will return three attributes:
- wasClean - boolean - When true, the connection closed normally and as expected.
- code - unsigned long - Status code from the server. For more info on the codes, see RFC 6455 section 7.4.1.
- reason - text - reason provided by the server.
This event can throw one of the following exceptions:
| Exception | Description |
|---|---|
| InvalidAccessError(15) | The code parameter is present but is not an integer equal to 1000 or in the range 3000 to 4999. |
| SyntaxError(12) | the reason parameter is longer than 123 bytes |
For more info on the WebSocket protocol, see:RFC 6455
See also
Show: