Datagram Transports

Datagrams are a self-contained unit of data. Each datagram carries with it the routing and context information needed to receive the data without knowing about any earlier exchanges of information. This means that you can continue sending datagrams from a source to a destination even if past datagrams along this path have been lost, duplicated, or misdirected. The protocol commonly associated with datagrams is the User Datagram Protocol (UDP) although it's possible to think of other transport protocols as having the same semantics as datagrams. For instance, when used in certain scenarios, queued transports and HTTP connections exhibit the same characteristics of datagram messaging as UDP.

There is a particular pattern that you can use when implementing datagram channels in WCF. The singleton channel has a one-to-one mapping between channel listeners and accepted channels. When receiving datagrams, it doesn't make sense to have multiple outstanding channels listening at the same address. Any channel would be equally as good as any other for delivery precisely because datagrams are self-contained without reference to any earlier exchanges. This has led to the singleton model, where the channel listener only ever proceeds to accept one active channel. That channel has to hold its own state because even though the channel and channel listener are one-to-one, the channel listener may be destroyed before the channel. Of course, if that singleton channel is ever closed, the channel listener can accept a new channel in its place. However, this new channel is indistinguishably identical to the old instance, and there's always only ever at most one channel in existence.

Next time: Advanced URL ACLing with Windows Vista