Skip to main content
MessageWebSocket.Close(UInt16, String) | close(UInt16, String) method

Applies to Windows and Windows Phone

Closes the MessageWebSocket object and indicates a reason for the closure.

Syntax


messageWebSocket.close(code, reason);

public void Close(
  ushort code, 
  string reason
)

Public Sub Close(
  code As UShort,  
  reason As String 
)

public:
void Close(
  unsigned short code, 
  String^ reason
)

Parameters

code

Type: Number [JavaScript] | System.UInt16 [.NET] | uint16 [C++]

Status code indicating the reason for closure.

The following values are supported:

ValueMeaning
1000

The purpose of the connection has been fulfilled and the connection is no longer needed.

1001

An endpoint is no longer available (such as when a server is no longer available or a browser has navigated away from a webpage).

1002

A protocol error has occurred.

1003

The endpoint cannot receive this type of data.

1005

An empty close frame was received.

Note  When code is set to 1005, the reason parameter must be an empty string. Setting code to 1005 will send an empty close frame.

1007

Data within a message is not consistent with the type of the message.

1008

The message violates an endpoint's policy.

1009

The message is too large to process.

1010

A client endpoint expected the server to negotiate one or more extensions, but the server didn't return them in the response message of the WebSocket handshake. The list of extensions that are needed should appear in the reason parameter.

 

Status codes in the range 0-999 are not used.

Status codes in the range 1000-2999 are reserved for definition by the WebSocket protocol.

Status codes in the range 3000-3999 are reserved for use by libraries, frameworks, and applications. These status codes are registered directly with IANA. The interpretation of these codes is undefined by the WebSocket protocol.

Status codes in the range 4000-4999 are reserved for private use and cannot be registered. Such codes can be used by prior agreements between WebSocket applications. The interpretation of these codes is undefined by the WebSocket protocol.

reason

Type: String [JavaScript] | System.String [.NET] | Platform::String [C++]

Optional UTF-8-encoded data with additional information about the closure.

Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.Networking.Sockets
Windows::Networking::Sockets [C++]

Metadata

Windows.winmd

DLL

Windows.Networking.dll

See also

MessageWebSocket
Close