locked
DatagramSocket: When I get MessageReceived, how do I actually read the data and who it was from? RRS feed

  • Question

  • http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.sockets.datagramsocket.messagereceived
    If I click on DatagramSocketMessageReceivedEventArgs from that page it just links to TypedEventHandler http://msdn.microsoft.com/en-us/library/windows/apps/br225997

    When I get MessageReceived, how do I actually read the data and who it was from?

    Tuesday, January 1, 2013 7:12 PM

Answers

  • Hi RakNet-Kevin,

    I think you are misinterpreting the documentation. An event is subscribed following way in datagram socket.

        DatagramSocket^ listener = ref new DatagramSocket(); 
        ListenerContext^ listenerContext = ref new ListenerContext(rootPage, listener); 
        listener->MessageReceived += ref new TypedEventHandler<DatagramSocket^, DatagramSocketMessageReceivedEventArgs^>(listenerContext, &ListenerContext::OnMessage); 

    Here OnMessage is the method which will be fired automatically when a datagrams are arrived. So you can receive datagrams inside this method. See the following example.

    DatagramSocket sample

    • Proposed as answer by Jesse Jiang Thursday, January 3, 2013 3:12 AM
    • Marked as answer by Jesse Jiang Tuesday, January 8, 2013 2:06 AM
    Wednesday, January 2, 2013 2:55 AM
  • Thanks for the link to the sample.

    The documentation does not link to this from the page I provided. The page I needed was

    http://msdn.microsoft.com/en-us/library/windows/apps/BR241344

    • Marked as answer by Jesse Jiang Tuesday, January 8, 2013 2:06 AM
    Wednesday, January 2, 2013 4:12 PM

All replies

  • Hi RakNet-Kevin,

    I think you are misinterpreting the documentation. An event is subscribed following way in datagram socket.

        DatagramSocket^ listener = ref new DatagramSocket(); 
        ListenerContext^ listenerContext = ref new ListenerContext(rootPage, listener); 
        listener->MessageReceived += ref new TypedEventHandler<DatagramSocket^, DatagramSocketMessageReceivedEventArgs^>(listenerContext, &ListenerContext::OnMessage); 

    Here OnMessage is the method which will be fired automatically when a datagrams are arrived. So you can receive datagrams inside this method. See the following example.

    DatagramSocket sample

    • Proposed as answer by Jesse Jiang Thursday, January 3, 2013 3:12 AM
    • Marked as answer by Jesse Jiang Tuesday, January 8, 2013 2:06 AM
    Wednesday, January 2, 2013 2:55 AM
  • Thanks for the link to the sample.

    The documentation does not link to this from the page I provided. The page I needed was

    http://msdn.microsoft.com/en-us/library/windows/apps/BR241344

    • Marked as answer by Jesse Jiang Tuesday, January 8, 2013 2:06 AM
    Wednesday, January 2, 2013 4:12 PM