Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Can the time it takes for a packet to be transmitted from a client to the server fluctuate?

share|improve this question
add comment

4 Answers

up vote 9 down vote accepted

The IP protocol, atop which TCP and UDP are constructed, specifies that datagrams are neither guaranteed to arrive in order, nor via the same route, nor, for that matter, at all (thanks Trevor for the reminder). So, irrespective of whether TCP or UDP is used, latency will fluctuate. Latency is partly due to distance travelled, which changes if the path changes, and partly due to protocol stack translation on the routing devices along the chosen path -- which also change if the path changes.

This is part of the self-repairing nature of the internet, enabling it to do what it does every day: if one route becomes less suitable according to heuristics programmed into various routing devices along the way, another route will be chosen instead. This can be either momentary, or long-term. Remember that before it was the internet, it was the ARPANET -- a defense network designed to deal with eg. the instant removal of vast sections of the network (think nuclear warfare), without the network as a whole going down. By routing around damaged or otherwise non-ideal areas, the greater network continues to function (albeit, perhaps, suboptimally).

share|improve this answer
1  
Worth adding that datagrams aren't guaranteed to arrive at all. They can just silently be dropped at any point along their journey. It's only TCP's transport built on top of IP that adds an illusion of reliability to network communications. –  Trevor Powell Dec 23 '11 at 3:23
    
Also see Danny Pflughoeft's answer, he rightly adds that TCP will suffer additional delays due to the way it operates -- if packets are lost, they'll be re-requested and resent, adding an additional full round trip time onto the message latency. And that can happen arbitrarily many times. UDP overcomes this by sending a continual stream of updates, and where the simulation can move ahead in spite of packet loss (much more to think about and plan for in this sort of system, however). –  Nick Wiggill Feb 10 '12 at 17:02
add comment

This is probably not game development question, but yes. In normal IP connection, each packets may go through different intermediary "hops", and each different "hops" may have different latency.

If you're using TCP to transfer your data, the protocol abstracts that for you and will reorder packets to deliver the packets in the order they were originally sent; however if you're using UDP, the packets can and do arrive out of order, depending on the latency of each individual packets.

share|improve this answer
    
In particular, if the UDP and TCP packets are being routed the same way and the UDP packets are routinely arriving out-of-order, this translates to "lag spikes" over the same connection using TCP instead. –  Martin Sojka Dec 22 '11 at 14:39
add comment

Absolutely everything about an IP network can change at any time.

The following article discusses how things like latency, packet loss, and throughput can vary and why: DEI Tech Note 0021: Loss, Latency, and Speed

share|improve this answer
add comment

Aside from what's already been said, don't forget that routers are allowed to arbitrarily drop packets, meaning in TCP a packet could theoretically take arbitrarily long to reach its destination (and in UDP, it might never reach its destination!).

share|improve this answer
1  
+1, Very important this. –  Nick Wiggill Feb 10 '12 at 17:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.