MessageWebSocket.MessageReceived Event

Definition

An event that indicates that a message was received on the MessageWebSocket object.

// Register
event_token MessageReceived(TypedEventHandler<MessageWebSocket, MessageWebSocketMessageReceivedEventArgs const&> const& handler) const;

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

// Revoke with event_revoker
MessageWebSocket::MessageReceived_revoker MessageReceived(auto_revoke_t, TypedEventHandler<MessageWebSocket, MessageWebSocketMessageReceivedEventArgs const&> const& handler) const;
public event TypedEventHandler<MessageWebSocket,MessageWebSocketMessageReceivedEventArgs> MessageReceived;
function onMessageReceived(eventArgs) { /* Your code */ }
messageWebSocket.addEventListener("messagereceived", onMessageReceived);
messageWebSocket.removeEventListener("messagereceived", onMessageReceived);
- or -
messageWebSocket.onmessagereceived = onMessageReceived;
Public Custom Event MessageReceived As TypedEventHandler(Of MessageWebSocket, MessageWebSocketMessageReceivedEventArgs) 

Event Type

Remarks

All message processing and connection related errors are communicated through the GetDataReader and GetDataStream methods. If either of these methods throws an exception, it indicates that either the underlying connection is broken, or the server has sent invalid data, such as corrupt HTTP headers or a message that exceeds the maximum message size. The appropriate action for your code to take in the face of an exception from these methods is to re-establish a known good state by closing the websocket, creating a new one, and reconnecting to the server.

All MessageReceived event handlers must be registered before ConnectAsync is called. After that, attempting to add or remove a MessageReceived event handler will fail with E_ILLEGAL_METHOD_CALL, even after the socket has been closed

An empty message results in GetDataReader returning a valid IDataReader instance with UnconsumedBufferLength set to 0. GetDataStream returns a valid IInputStream instance that yields zero bytes.

Applies to