Receive UDP Broadcast

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

Does anyone have an example of how to receive a connectionless(udp)
broadcast in c#. I have tried everything i can possibly think of and
it won't recieve the message. I know that the message is coming in and
that its not being blocked because there is another app on my machine
that is getting the message. Please help.
 
Hello Dave,

See there http://samples.gotdotnet.com/quickstart/howto/doc/TCPUDP/BroadcastChatClient.aspx

D> Does anyone have an example of how to receive a connectionless(udp)
D> broadcast in c#. I have tried everything i can possibly think of and
D> it won't recieve the message. I know that the message is coming in
D> and that its not being blocked because there is another app on my
D> machine that is getting the message. Please help.
D>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/members/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
I can show you how I do it, but I've never been properly trained in
network coding, so this might not be the best way.

ing udpPort = 8085;

UdpClient clientListener = new UdpClient(udpPort);
IPEndPoint anyone = new IPEndPoint(IPAddress.Any, 0);

byte[] data = clientListener.Receive(ref anyone);

Note that this method will block on the .Receive until something is
received, so you might want to do this in a seperate thread and then
pass the byte array back to your main thread. Also, I've found that I
don't really like Udp much and have switched mostly to Tcp type
programming, but Udp does have its advantages. I hope this helps, let
me know if you want to see some more code.
 
Back
Top