
An actual valid address.
I am unable to reproduce your problem. Using code that does exactly what
the code you posted does, if I enter an IP address in the textbox that
matches my local IP address, that succeeds. If I enter "0.0.0.0"
(essentially, the IPAddress.Any address), that succeeds. If I enter an IP
address other than those two, I get the exception you're describing, but
then that's expected in that case.
So, I suspect that you are not entering a valid address, in spite of
whatever belief you have that you are.
I agree that the MSDN samples are not necessarily the best. However, I
looked at three different pages, UdpClient.Receive(IPEndPoint),
Socket.Receive(byte[]), and Socket.ReceiveFrom(byte[], EndPoint), and in
each case the sample is either incomplete (so you would need to look
elsewhere for the initialization) or it _does_ bind the socket.
Specifically, the Socket.Receive(byte[]) page doesn't include an explicit
bind, but the documentation says right at the top that it's to be called
on a bound socket. The other two pages do bind the object (UdpClient in
the first case, Socket in the second) in the sample code provided.
In other words, yes you do need to bind the socket, and the documentation
is actually reasonably clear on this, at least where I looked. If you
found somewhere else that it's not clear, file a comment with a rating for
the page and hopefully Microsoft will fix it.
By the way, I'm a little confused as to why you're using the UdpClient
class. You seem to be trying to get at the lower level, using the Socket
directly. If you're going to do that, why not just create a UDP Socket
and use that?
Pete