Accurate UDP connection
-
Hello, I'm trying to read messages from an outside source that orks on 30HZ (every 33 msec there is a new message). I tried to use the udp classes in .Net but I discovered that althogh 80% of the time the messages reciveing interval is about 33 msec, sometimes i get picks of 50 and more. 1. How would you solve it ? 2. Is it beacuse it is a UDP connection ? 3. Can I recieve in a diffrent way (using dllimport to some udp recieving dll for example ?). thanks,
-
Hello, I'm trying to read messages from an outside source that orks on 30HZ (every 33 msec there is a new message). I tried to use the udp classes in .Net but I discovered that althogh 80% of the time the messages reciveing interval is about 33 msec, sometimes i get picks of 50 and more. 1. How would you solve it ? 2. Is it beacuse it is a UDP connection ? 3. Can I recieve in a diffrent way (using dllimport to some udp recieving dll for example ?). thanks,
You're using an inaccurate clock. The Windows tick timer (
Environment.TickCount
) ticks at a frequency of around 15-16ms, so you will normally see durations measured with this timer as being some multiple of 16ms. Try using theStopwatch
class instead, if using .NET 2.0 or later. That said, UDP is always susceptible to network delays. Routers can delay or drop packets if a link is saturated. LANs will drop packets and have to retransmit if two stations try to send at the same time (this is referred to as a collision). You would need a dedicated link to avoid the possibility of a collision.DoEvents: Generating unexpected recursion since 1991
-
You're using an inaccurate clock. The Windows tick timer (
Environment.TickCount
) ticks at a frequency of around 15-16ms, so you will normally see durations measured with this timer as being some multiple of 16ms. Try using theStopwatch
class instead, if using .NET 2.0 or later. That said, UDP is always susceptible to network delays. Routers can delay or drop packets if a link is saturated. LANs will drop packets and have to retransmit if two stations try to send at the same time (this is referred to as a collision). You would need a dedicated link to avoid the possibility of a collision.DoEvents: Generating unexpected recursion since 1991