DatagramSocket.MessageReceived Event
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
An event that indicates that a message was received on the DatagramSocket object.
// Register
event_token MessageReceived(TypedEventHandler<DatagramSocket, DatagramSocketMessageReceivedEventArgs const&> const& handler) const;
// Revoke with event_token
void MessageReceived(event_token const* cookie) const;
// Revoke with event_revoker
DatagramSocket::MessageReceived_revoker MessageReceived(auto_revoke_t, TypedEventHandler<DatagramSocket, DatagramSocketMessageReceivedEventArgs const&> const& handler) const;
public event TypedEventHandler<DatagramSocket,DatagramSocketMessageReceivedEventArgs> MessageReceived;
function onMessageReceived(eventArgs) { /* Your code */ }
datagramSocket.addEventListener("messagereceived", onMessageReceived);
datagramSocket.removeEventListener("messagereceived", onMessageReceived);
- or -
datagramSocket.onmessagereceived = onMessageReceived;
Public Custom Event MessageReceived As TypedEventHandler(Of DatagramSocket, DatagramSocketMessageReceivedEventArgs)
Event Type
Windows requirements
App capabilities |
ID_CAP_NETWORKING [Windows Phone]
|
Remarks
To receive data on the DatagramSocket object, an app must assign the [MessageReceived event to an event handler and then call either the BindEndpointAsync or BindServiceNameAsync method to bind the DatagramSocket to a local service name or UDP port. The ConnectAsync methods will also result in a bind operation. Writing to a stream returned by one of the GetOutputStreamAsync methods will also result in a bind operation. The MessageReceived event handler will be invoked whenever a message from a remote endpoint arrives.
To receive multicast packets on the DatagramSocket object, an app must assign the [MessageReceived event to an event handler and then call the JoinMulticastGroup method to join the multicast group.
To unregister the [MessageReceived event, the DatagramSocket object must be closed. The Close method is used by Windows app using JavaScript. For apps written using the .NET Framework 4.5 in C# and VB.NET, the Close method is exposed as the method on the DatagramSocket. For apps written in C++, the Close method will be called when using the delete keyword on the object.