locked
Datagram Socket receive from any sender

    Question

  • From:

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

    "With the GetOutputStreamAsync methods, the app will receive packets from any remote destination sent to the local service name or UDP port."
    If I were to create a DatagramSocket, set the event handler, and bind it, I will get datagrams from any remote destination?

    But once I call ConnectAsynch, I will only get datagrams from that system from then on? So assuming I always want to receive datagrams from any remote destination, I should never use ConnectAsynch?

    Tuesday, January 01, 2013 7:11 PM

Answers

  • Hi,

    Hope this statements can explain well for you:

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

    If the app wants to receive data from any remote endpoint on the DatagramSocket object, the ConnectAsync method should not be used since this binds the DatagramSocket to a specific remote endpoint. Instead the BindServiceNameAsync or BindEndpointAsync method should be used.
              


    Regards,
    Christian HL
    Microsoft Online Community Support


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    • Marked as answer by Jesse Jiang Tuesday, January 15, 2013 4:54 AM
    Monday, January 07, 2013 9:35 AM

All replies

  • Please read the documentation thoroughly that you mentioned. I think you are almost right.

    The GetOutputStreamAsync methods allow an app to send UDP datagrams using a DatagramSocket object to multiple network destinations. Each time the GetOutputStreamAsync method is called, the app can set different values for the remoteHostName and remoteServiceName parameters.

    The GetOutputStreamAsync methods also differ from the ConnectAsync method when an app uses the BindEndpointAsync or BindServiceNameAsync method to bind the local service name or UDP port. With theGetOutputStreamAsync methods, the app will receive packets from any remote destination sent to the local service name or UDP port. With the ConnectAsync methods, the app will only receive packets from the remote destination passed as parameters to the ConnectAsync methods.

    Wednesday, January 02, 2013 2:30 AM
  • "Any remote destination sent to the local service name or UDP port" could be interpreted as any system I previously sent to. However, I want to get datagrams from any system, not just those I previously sent to.

    Does anyone have an answer on this?

    Wednesday, January 02, 2013 4:07 PM
  • Hi,

    Hope this statements can explain well for you:

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

    If the app wants to receive data from any remote endpoint on the DatagramSocket object, the ConnectAsync method should not be used since this binds the DatagramSocket to a specific remote endpoint. Instead the BindServiceNameAsync or BindEndpointAsync method should be used.
              


    Regards,
    Christian HL
    Microsoft Online Community Support


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    • Marked as answer by Jesse Jiang Tuesday, January 15, 2013 4:54 AM
    Monday, January 07, 2013 9:35 AM