Share via


MessageWebSocket.Closed Event

Definition

Occurs when a close frame is received on the MessageWebSocket object as part of the close handshake.

// Register
event_token Closed(TypedEventHandler<IWebSocket, WebSocketClosedEventArgs const&> const& handler) const;

// Revoke with event_token
void Closed(event_token const* cookie) const;

// Revoke with event_revoker
MessageWebSocket::Closed_revoker Closed(auto_revoke_t, TypedEventHandler<IWebSocket, WebSocketClosedEventArgs const&> const& handler) const;
public event TypedEventHandler<IWebSocket,WebSocketClosedEventArgs> Closed;
function onClosed(eventArgs) { /* Your code */ }
messageWebSocket.addEventListener("closed", onClosed);
messageWebSocket.removeEventListener("closed", onClosed);
- or -
messageWebSocket.onclosed = onClosed;
Public Custom Event Closed As TypedEventHandler(Of IWebSocket, WebSocketClosedEventArgs) Implements Closed

Event Type

Implements

Remarks

This event is only triggered if a close frame is received from the server or if Close is explicitly called on the local socket. If the underlying TCP connection is suddenly terminated, GetDataReader and/or GetDataStream throw the WININET_E_CONNECTION_ABORTED exception, without the Close event ever being raised.

Your code should handle aborted connections by first closing and disposing of the current MessageWebSocket object (as it is now useless), and then performing whatever other steps are appropriate for your app, such as creating a new MessageWebSocket and trying to connect again.

Applies to

See also