Register  |  Login




Advertisement

Start Your Own Q&A Site

Create your own Q&A site easily, allowing you to quickly grow a new community around any subject matter or generate new organic traffic for your existing website.

Question

Status: Open Points: 75 Time: 08:48 - Nov 10, 2009  

gauravsagargupta

Hi All I am facing prob in UDP Broadcasting using C#. I am using 2 pc connected in LAN.Please Help

Hi
I am trying to broadcast(UDP) a message on LAN using C#.I have connected systems(P2P connection).I am able to send and receive broadcast message on 1st pc but unable to see the same result on 2nd pc.Please Help

My code is

For Receiving Broadcast Message..
soc = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IPEndPoint iep = new IPEndPoint(IPAddress.Any, 9999);
soc.Bind(iep);
EndPoint ep = (EndPoint)iep;
soc.EnableBroadcast = true;


byte[] buffer;
while (true)
{
buffer = new byte[1024];
soc.Receive(buffer);
string bufferstr = null;
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
bufferstr = enc.GetString(buffer);

}

For Broadcasting Message...
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1);

IPEndPoint iep = new IPEndPoint(IPAddress.Broadcast, 9999);
string message;

byte[] data = Encoding.ASCII.GetBytes(message);
sock.EnableBroadcast = true;
sock.SendTo(data, iep);
Thread.Sleep(3000);
sock.Close();

Categories

Answer Discussion
Tutorials

 

This question has not yet been answered.

Answer this Question

New User

Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:

Forgot Your Password?

Tutorials cannot be submitted until the Answer Discussion is complete.

Submit answers in the Answer Discussion area

Ask a Question

Have a new question? Ask!

You have 100 characters to use



Top Experts

View More

Rank

Expert

Points

1.

nidhi

10279

2.

oracleofDelphi

6493

3.

rcastagna

5596

4.

LAGM

4848

5.

PeterNZ

3487

6.

gonzalo

2840

7.

Mason

2770

8.

jgivoni

2303

9.

xarcus

1820

10.

Anpanman

917

Become an Expert

Register today to share your knowledge with the community and be recognized and rewarded for your contributions.


Register Here




"Psst, Quomon is a great site. Pass it on."     Tell a Friend  |   Link To Us  |   Save to Delicious  |   Digg! Digg it



Language Options

English:

www.quomon.com

Español:

www.quomon.es