简体   繁体   中英

receive all udp packets on multicast

i am using the c# UdpClient (client in code) to receive data on a multicast group. In a while loop the follwing happens:

while(receiving)
    //First i check if data is available, polltime = 100ms
    if(client.Client.Poll(polltime, SelectMode.SelectRead))
    {
        //if data is present 
        data = client.Receive(ref remoteEp);
        ...
    }
    else
    {
        //100ms
        Thread.sleep(sleeptime);
    }

somehow i often miss packets (if there are more than one) that should be on the multicast and udp packet loss can´t be that much i guess. Can the receiving be done better or does anyone know the problem)

Edit1: The data that is sent are also by c# UdpClient and are byte arrays with the siz of 1024

Edit2: In Wireshark i could see that the missing packets are not arriving, so the problem may be really udp packet loss?

I'd suggest the following implementation of the receive loop:

while (receiving)
{
    try
    {
        // block until data is present
        data = client.Receive(ref remoteEp);
        ...
    }
    catch (SocketException ex)
    {
        receiving = false;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM