Receive UDP Data

J

Joris Dobbelsteen

Currently I'm developing a simple application under the .NET platform,
however I seem to be unable to perform even the simplest things.

The application must be able to discover whether a server is running, so it
sends a UDP packet to a the 255.255.255.255 broadcast address. (Currently
this is 192.168.10.255 because of security issues?) Finally gotting the IP
addressed interpreted (IPAddress.Parse(string)).

My question is how to use the (System.Net.Sockets.) Socket object to
retreive any number of UDP packets (0 or more).
What function can be used to check for (pending) incoming packets?
What function can be used to retreive the IP of system sending the socket?

The routines BeginReceive and Endreceive can do the job, however they seem
to make the work significantly more complex that should be neacessary.
Should I go with this solution or is there a synchronous routine available
to perform this task?

- Joris
 
N

Nicholas Paldino [.NET/C# MVP]

Joris,

You can just call Receive, instead of BeginReceive and EndReceive.
However, if your app is receiving multiple requests, then you are definitely
going to get hit performance-wise by not using the asynchronous methods.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top