Answered by:

Datagram Socket receive from any sender

Question

"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 1, 2013 7:11 PM

Answers

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.

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.

"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.

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.