Search code examples
c#udpclient

udpclient.receive() suddenly stops receiving



I'm using UdpClient to receive data from a single host(actually it's a microcontroller that sends 32 bytes of data every 4 milliseconds.
The program I wrote is pretty simple.
I'm initializing the UdpClient like this(in Program.cs):

public static UdpClient client = new UdpClient(1414);

after that i do this in Form_Load event:

static UdpClient client = Program.client; 
IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);

and then call the client.Recieve() like this:

                Task.Run(() =>
                {
                    while (true)
                    {                       
                        try
                        {
                            data = client.Receive(ref RemoteIpEndPoint);                            
                        }
                        catch (Exception ex)
                        {
                            String err_type = ex.GetType().Name;
                            if (err_type == "SocketException")
                            {                                    
                                MessageBox.Show("Cannot Find The Device.", "Device Error.");
                            }
                        }                                                        
                    }
                });

the program runs fine on my own system (using Windows 10). However when i run this program on windows 7,at random times,but with 100% chance client.Recieve() stops working and the program no longer receives any data. no exception is thrown. to find the root of the problem, I installed Wireshark to test if there is any incoming data.The answer was no(the LAN port light stops blinking too) . What has me confused is that this does not happen on windows 10.


Solution

  • Turns out my code was completely fine.
    This was a hardware problem on our side.