UDP socket.RemoteEndPoint

I am trying to catch some broadcast packets from some other devices on the network. When I try to get the socket.RemoteEndPoint so I can get the IP address of the device that sent the broadcast I get and error. If I remove that line it continues on as it should and the data from the device is readable.
What am I doing wrong?

Exception System.InvalidOperationException - CLR_E_INVALID_OPERATION (8)

Message:

GHIElectronics.TinyCLR.Devices.Network.Provider.NetworkControllerApiWrapper::GetRemoteAddress [IP: 0000]

System.Net.Sockets.Socket::GetEndPoint [IP: 003d]

System.Net.Sockets.Socket::get_RemoteEndPoint [IP: 0005]

    int port = 5556;
    var ipEndPoint = new IPEndPoint(IPAddress.Any, port);
    var socket = new Socket(System.Net.Sockets.AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
    byte[] data = new byte[1024];
    string name;

    try
    {
        socket.Bind(ipEndPoint);
        while (true)
        {
            while(!socket.Poll(10,SelectMode.SelectRead))
            {
                Thread.Sleep(10);
            }
            var available = socket.Available;
            Debug.WriteLine("Network data: " + available.ToString() );
            if (available == 0) break;
            Debug.WriteLine("Network: " + socket.RemoteEndPoint.ToString());//<----Error happens here.
            
            socket.Receive(data);
            name = Encoding.UTF8.GetString(data, 374, 24);
            Debug.WriteLine(name);
            
        }
    }
    catch (Exception ex)
    {
        Debug.WriteLine("Network: " + ex.Message);
    }

Try reading the packet before looking at the endpoint. It is possible that there are several packets in the buffer.Therefore, you need a context (a read packet) to get the remote address.

Thanks for the suggestion, it led me to the following code that appears to work. Used ReceivedFrom(), I passed the EndPoint created from the existing IPEndPoint and on return it updated it with the client IP address and port. (There was a fair bit of “googling” to get there as well.)

    int port = 5556;
    var ipEndPoint = new IPEndPoint(IPAddress.Any, port);
    var socket = new Socket(System.Net.Sockets.AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
    byte[] data = new byte[1024];
    string name;

    try
    {
        socket.Bind(ipEndPoint);
        while (true)
        {
            while(!socket.Poll(10,SelectMode.SelectRead))
            {
                Thread.Sleep(10);
            }
            var available = socket.Available;
            Debug.WriteLine("Network data: " + available.ToString() );
            if (available == 0) break;

            EndPoint ep = (IPEndPoint)ipEndPoint;
                               
            socket.ReceiveFrom(data,ref ep);
            Debug.WriteLine("From IP: " + ep.ToString());
            name = Encoding.UTF8.GetString(data, 374, 24);
            Debug.WriteLine(name);
            
        }
    }
    catch (Exception ex)
    {
        Debug.WriteLine("Network: " + ex.Message);
    }

Does it work twice?

It picks up all 4 devices that are broadcasting on the network as it should. They broadcast every second.