DatagramSocket.MessageReceived DatagramSocket.MessageReceived DatagramSocket.MessageReceived DatagramSocket.MessageReceived DatagramSocket.MessageReceived Event

Definition

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

public : event TypedEventHandler<DatagramSocket, DatagramSocketMessageReceivedEventArgs> MessageReceived
// Register
event_token MessageReceived(TypedEventHandler<DatagramSocket, DatagramSocketMessageReceivedEventArgs> const& handler) const;

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

// Revoke with event_revoker
MessageReceived_revoker MessageReceived(auto_revoke_t, TypedEventHandler<DatagramSocket, DatagramSocketMessageReceivedEventArgs> const& handler) const;
public event TypedEventHandler<DatagramSocket, DatagramSocketMessageReceivedEventArgs> MessageReceived
Public Event MessageReceived As TypedEventHandler (Of DatagramSocket, DatagramSocketMessageReceivedEventArgs)
function onMessageReceived(eventArgs){/* Your code */}


datagramSocket.addEventListener("messagereceived", onMessageReceived);
datagramSocket.removeEventListener("messagereceived", onMessageReceived);

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.

See also