UDP Socket Receiver stops receiving

Hi,

I have an application on the EMX which uses UDP to communicate to a server and other EMX devices. I have found that under a particular scenario the UDP Receiver stops receiving data.

My application sends data in blocks to the server, the whole data block is around 19kb. I send this datablock in small UDP packets no bigger than 1371 bytes.
After i have sent all the UDP packets that make up a datablock (around 15 packets), i receive a ACK packet from the server which is 167 bytes long.

My application will continually sends data blocks to the server, after running for a while the device stops receiving the ACK messages from the server.

I have verified that the problem is not with the server i.e by restarting it and also by using wireshark captures which show the ACK’s coming through. However the device does not receive the ACK’s after some point in time. It also seems that the failure is always occurring a the same point. i.e .after sending the 7th block.

Below is the code for the UDP Receiver, can anyone see why i have this issue or can reproduce the problem.


namespace SmartNode.Udp.Sockets
{
    public delegate void UdpDataReceived(ReceivedUdpData data);
    public class UdpRecvSocket:IModule
    {
        public int Port { get; private set; }
        public event UdpDataReceived OnDataReceived;

        private ILogger Log;
        private EndPoint _ipEndPoint;
        private Socket _socket;
        private Thread _rxThread;

        public UdpRecvSocket() : this(62001){}

        public UdpRecvSocket(int port)
        {
            Port = port;
            Log = LogManager.GetLogger("UdpRecvSocket-" + Port);
            _socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            _ipEndPoint = new IPEndPoint(IPAddress.Any, Port);
            _socket.Bind(_ipEndPoint);
            _rxThread = new Thread(RxMessageProcessor);
        }

        private void RxMessageProcessor()
        {
            
            EndPoint from = new IPEndPoint(0, 0);
            while (true)
            {
                
                if (_socket.Poll(-1, SelectMode.SelectRead))
                {
                    Thread.Sleep(10);
                    
                    var data = new byte[_socket.Available];

                    //int cnt = socket.ReceiveFrom(data, data.Length, SocketFlags.None, ref from);
                    
                    int cnt = _socket.ReceiveFrom(data, ref from);

                    if(Port == 62001)
                        Log.Info("Received " + cnt + "bytes from " + from);

                    if (cnt == 0)
                    {
                        Thread.Sleep(10);
                        continue;
                    }

                    var recv = new ReceivedUdpData
                    {
                        Data = new byte[cnt],
                        Host = from.ToString().Split(':')[0],
                        Port = Port
                    };

                    Array.Copy(data, 0, recv.Data, 0, cnt);
                    
                    if(OnDataReceived != null)
                    {
                        OnDataReceived(recv);
                    }
                    
                }
            }
        }

        public void Start()
        {
            _rxThread.Start();
        }

        public void Stop()
        {
            throw new NotImplementedException();
        }
    }
}

Did you try to run it under debugger and see if there are any hints in the output window?