Collapse the table of content
Expand the table of content

close method

Closes a WebSocket connection.


object.close(code, reason)


code [in, optional]

Type: Number

reason [in, optional]

Type: DOMString

Return value

This method does not return a value.


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:

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

WebSockets in Windows
WebSockets RFC 6455
The WebSocket API



© 2015 Microsoft