Learning Python Network Programming

(Sean Pound) #1

Network Programming and Python


TCP also includes algorithms which ensure that traffic is not sent too quickly for the
receiving device to process, and these algorithms also infer network conditions and
regulate the transmission rate to avoid network congestion.


Together these services provide a robust and reliable transport system for application
data. This is one of the reasons many popular higher level protocols, such as HTTP,
SMTP, SSH, and IMAP, depend on TCP.


UDP versus TCP

Given the features of TCP, you may be wondering what the use of a connectionless
protocol like UDP is. Well, the Internet is still a pretty reliable network, and most
of the packets do get delivered. The connectionless protocols are useful where the
minimum transfer overhead is required, and where the occasional dropped packet is
not a big deal. TCP's reliability and congestion control comes at the cost of needing
additional packets and round-trips, and the introduction of deliberate delays when
packets are lost in order to prevent congestion. These can drastically increase latency,
which is the arch-nemesis of real-time services, while not providing any real benefit
for them. A few dropped packets might result in a transient glitch or a drop in signal
quality in a media stream, but as long as the packets keep coming, the stream can
usually recover.


UDP is also the main protocol that is used for DNS, which is interesting because
most DNS queries fit inside a single packet, so TCP's streaming abilities aren't
generally needed. DNS is also usually configured such that it does not depend upon
a reliable connection. Most devices are configured with multiple DNS servers, and
it's usually quicker to resend a query to a second server after a short timeout rather
than wait for a TCP back-off period to expire.


The choice between UDP and TCP comes down to the message size, whether
latency is an issue, and how much of TCP's functionality the application wants
to perform itself.


Layer 5 – The application layer


Finally we come to the top of the stack. The application layer is deliberately left open
in the IP protocol suite, and it's really a catch-all for any protocol that is developed
by application developers on top of TCP or UDP (or even IP, though these are rarer).
Application layer protocols include HTTP, SMTP, IMAP, DNS, and FTP.

Free download pdf