I am trying to write code the receives broadcast messages coming from another app. using wireShark, I can see that they are sent to 255.255.255.255:300.
I tried the following code:
IPEndPoint ServerEndPoint = new IPEndPoint(IPAddress.Any, 3000);
Socket WinSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
WinSocket.Bind(ServerEndPoint);
byte[] data = new byte[10];
Console.Write("Waiting for client");
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
EndPoint Remote = (EndPoint)(sender);
int recv = WinSocket.ReceiveFrom(data, ref Remote);
Console.WriteLine("Message received from {0}:", Remote.ToString());
string str = Encoding.ASCII.GetString(data, 0, recv);
but when my app reached to the "bind" command there is an error message: "Only one usage of each socket address (protocol/network address/port) is normally permitted"
if I change the port there is no error but I catch nothing.
Please advice