UDP buffer in C# on XP
I have a continuous stream of udp pack开发者_运维技巧ets to a computer running windows xp. At some point I start a listener (written in C#) that handles the udp packets received.
When I start the listener, will I get packets that were sent before the listener was started due to a buffer, or can I be certain that the first packet I get into my listener is actually the first packet received since the listener was started?
UDP delivery is not guaranteed to arrive in order, to arrive at all, to arrive only once, or to arrive after a certain time.
Therefore, you'll need to also handle UDP packets that have been sent before you started listening to the port, but for some reason took a world tour and did not arrive until after you started listening.
In most O/S implementations, when a UDP packet arrives to a port (and it is not broadcast) and there is no one listening on UDP on that port, the packet gets discarded. However, there is a chance that a UDP packet arrives at the O/S and gets queued in the network driver's internal buffer, before the O/S has a chance to process it when your listener starts. Then you'll also see it.
In general, never assume anything reliable to come from UDP packets.
精彩评论