0

I am trying to get a multicast UDP receiver working in a windows form in c#

I have found the following code online

Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,ProtocolType.Udp);
IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 2237);
s.Bind(ipep);
IPAddress ip = IPAddress.Parse("239.255.0.1");

s.SetSocketOption(SocketOptionLevel.IP,SocketOptionName.AddMembership,new MulticastOption(ip, IPAddress.Any));
byte[] b = new byte[1024];
s.Receive(b);
string str = System.Text.Encoding.ASCII.GetString(b, 0, b.Length);
Console.WriteLine(str.Trim());

Which from what I have read should work. My problem is I get the following error

"An unhandled exception of type 'System.Net.Sockets.SocketException' occurred in System.dll Additional information: Only one usage of each socket address (protocol/network address/port) is normally permitted"

This error is generated at the line

s.Bind(ipep);

The multicast IP address and port are controlled by other software, which is already working NOT written by me, and UDP packet is already being received by 2 other programs also NOT written by me

This is out of my area of knowledge if anyone can help I would be grateful

Thanks David

  • Does this answer your question? [Receiving UDP Multicast Messages on a Multihomed Windows 10 Machine](https://stackoverflow.com/questions/51860595/receiving-udp-multicast-messages-on-a-multihomed-windows-10-machine) – IamK Sep 25 '22 at 22:31

0 Answers0