Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I've a big problem:
i'm sending UDP pkt from a micro to a pc.
In the pkt I send there is a counter. I send 1Kbyte pkt at 100 Hz.
When I receive the pkt from the pc I lose some pkt. I see that because I increase a counter every time I receive one of them and this number is different from the counter I send. this difference increase ever.
Have anyone the some problem? How can I solve it?
My OS is Windows XP and I'm using Visual C++ 2010 Express.
The function I'm using for receive the pkt is recvfrom.
Posted
Comments
ely_bob 19-Jul-10 15:37pm    
Are you sure your systems are little/big endian compatible?

1 solution

From User Datagram Protocol[^]):

UDP uses a simple transmission model without implicit hand-shaking dialogues for guaranteeing reliability, ordering, or data integrity. Thus, UDP provides an unreliable service and datagrams may arrive out of order, appear duplicated, or go missing without notice. UDP assumes that error checking and correction is either not necessary or performed in the application, avoiding the overhead of such processing at the network interface level. Time-sensitive applications often use UDP because dropping packets is preferable to waiting for delayed packets, which may not be an option in a real-time system. If error correction facilities are needed at the network interface level, an application may use the Transmission Control Protocol (TCP) or Stream Control Transmission Protocol (SCTP) which are designed for this purpose.

Be aware that Windows systems usually are not able to ensure I/O latencies smaller than some milliseconds, and 100 Hz has to be considered a sustained frequency for standard applications.

What to do is highly dependant on your requirements; you can:


  • make your application fault tolerant: this is possible only if it is acceptable to loose some datagram
  • change the transmission protocol, for instance to TCP/IP: this requires to implement a more complicated protocol on your micro, then it depends on its resources and on the platform that you use on it (see CMX Systems, Inc[^] for an example of TCP/IP implementation for 8, 16 and 32-bit micro)
  • use real-time extensions for Windows, like Ardence RTX (see IntervalZero - RTX[^]): this way you are able to write Windows applications with strict timing behaviours, and probably you will be able to work with UDP packets without problems
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900