Receive UDP Broadcast

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

Michael Nemtsev

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
 
J

Justin Creasy

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.
 

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