Skip to main content
MessageWebSocket.MessageReceived | messagereceived event

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

Syntax


function onMessageReceived(eventArgs) { /* Your code */ }
 
// addEventListener syntax
messageWebSocket.addEventListener("messagereceived", onMessageReceived);
messageWebSocket.removeEventListener("messagereceived", onMessageReceived);
 
- or -

messageWebSocket.onmessagereceived = onMessageReceived;

public event TypedEventHandler<MessageWebSocket, MessageWebSocketMessageReceivedEventArgs> MessageReceived

Public Event MessageReceived As TypedEventHandler(Of MessageWebSocket, MessageWebSocketMessageReceivedEventArgs)

public:
event TypedEventHandler<MessageWebSocket, MessageWebSocketMessageReceivedEventArgs>^ MessageReceived {
   Windows::Foundation::EventRegistrationToken add(TypedEventHandler<MessageWebSocket, MessageWebSocketMessageReceivedEventArgs>^ value);
   void remove(Windows::Foundation::EventRegistrationToken token);
}

Event information

Delegate TypedEventHandler<MessageWebSocket, MessageWebSocketMessageReceivedEventArgs>

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.

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.

Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

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

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (Windows 8.x and Windows Phone 8.x)

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

See also

MessageWebSocket