2

I'm having trouble in receiving the packets from UdpClient Socket.

Problem:

My socket is receiving the packets sent as broadcast type however it also receives the packets that it sends itself. How to stop this?

I have enabled the Broadcast for sending messages as broadcast and disabled the MulticastLoopback but the problem still persists.

Here is how my code snippet looks like:

UdpClient = new System.Net.Sockets.UdpClient();
UdpIpEp = new IPEndPoint(IPAddress.Parse("10.9.210.110"), 15000);
newIpendpoint = new IPEndPoint(IPAddress.Broadcast, 15000);

UdpClient.EnableBroadcast = true;
UdpClient.MulticastLoopback = false;
UdpClient.Client.Bind(UdpIpEp);

// for sending
UdpClient.Send(Data, Data.Length, newIpendpoint);

// for receiving
if (UdpClient.Available > 0) {
  Byte[] TempByteArray = UdpClient.Receive(ref UdpIpEp);
}

Now the data received in TempByteArray is same which is sent by the application. What am i doing wrong and how to stop it?

ankur
  • 85
  • 1
  • 2
  • 12

0 Answers0