MessageWebSocket.Closed MessageWebSocket.Closed MessageWebSocket.Closed MessageWebSocket.Closed MessageWebSocket.Closed Event


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

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

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

// Revoke with event_revoker
Closed_revoker Closed(auto_revoke_t, TypedEventHandler<IWebSocket, WebSocketClosedEventArgs> const& handler) const;
public event TypedEventHandler<IWebSocket, WebSocketClosedEventArgs> Closed
Public Event Closed As TypedEventHandler (Of IWebSocket, WebSocketClosedEventArgs)
function onClosed(eventArgs){/* Your code */}

messageWebSocket.addEventListener("closed", onClosed);
messageWebSocket.removeEventListener("closed", onClosed);


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.

See also