Hi all, I have two questions.

- Does htonl does the same thing as bswap? If it does, then is a waste of cycles calling it.

- What do you do when you receive udp packets out of order? Shall I just dump them?
Posted on 2001-12-10 12:43:16 by dxantos
#1 - YES ... htonl == bswap
(incidently, ntohl does EXACTLY the same thing .. hows THAT for redundant? LMAO) Remember the API was intended for high level languages (read C) and is full of such redundancies .. thus the term Optimization really is the domain of us lowrevellers(sic)

#2 - Man lets think before we act so rashly as to simply dump those out of order packets... you may have noticed some internet games and utilities use udp for (gasp) file transfers !!!
Two very good reasons...
A)Most ethernets operate on a collision-avoidance principle, meaning that your machine listens for a break before it starts yakking on the wire... should it detect someone else is yakking before it has completed, it will shut up and keep waiting to retry as that packet was just corrupted... therefore, smaller packets means we can effectively squeeze more onto the wire as we can fit into smaller gaps between other users' packets without causing retransmissions for ourself and other users.
B)Most Network Stacks are faster with udp data than with tcp data so there is only network latency to worry about, not local latency.

All this means we can get a faster transmission to occur, if ONLY we can ensure all those udp packets get to the destination, and (please note this) are re-organized when they arrive.
What you do then is implement a little homemade protocol on top of udp, simply put we are going to add some rules to the udp transfer in order to ensure the above conditions are met.
We need to be able to determine 3 things
1)dropped or corrupted packets that need retransmitting
2)out of order packets that need to be rearranged on the fly
3)Complete and successful transmission and time to finish up

How you do it is up to you, I've seen several mechanisms to determine dropped packets, the main ones are these:
marking the payload data with a displacement variable (wheres this data belong ??) and using either a timer with acks being sent, or using a more sophisticated out-of-sequence detector which will accept packets regardless of their displacement until the error becomes too great, then request individual retransmissions in the ack using the displacement tag
or my own personal method (for files that will fit in memory) of simply sending all packets, ignoring what gets dropped, and at the end of the run, the receiving client requests blocks of dropped packets where they are sequential, or singly if they are not sequential. Using Homer Method u may find a file takes 3 or 4 passes in this style, but generally it requires less acks for dropped packets, and they can be sent in one hit. What if the server drops some or all of the acks? Hows it know what to retransmit? Well if it drops some, the procedure will repeat, and those acks NOT dropped will be retransmitted, leaving some for the next run... if ALL are dropped, then the client relies on a Timer to re-request those pesky packets.
Posted on 2001-12-21 05:50:45 by Homer