Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions




Chapter 36. Programs: Clients, Servers, the Internet and the World Wide Web

The World-Wide Web is a metaphorical description for the sophisticated interactions among computers. The core technology that creates this phenomenon is the Internetworking Protocol suite, sometimes called The Internet. Fundamentally, the internetworking protocols define a relationship between pieces of software called the client-server model . In this case some programs (like browsers) are clients. Other programs (like web servers, databases, etc.) are servers.

This client-server model of programming is very powerful and adaptable. It is powerful because it makes giant, centralized servers available to large numbers of remote, widely distributed users. It is adaptable because we don't need to send software to everyone's computer to make a change to the centralized service.

Essentially, every client-server application involves a client application program, a server application, and a protocol for communication betweem the two processes. In most cases, these protocols are part of the popular and enduring suite of internetworking protocols based on TCP/IP. For more information in TCP/IP, see Internetworking with TCP/IP [Comer95].

We'll digress into the fundamentals of TCP/IP in the section called “About TCP/IP”. We'll look at what's involved in a web server in the section called “Web Servers and the HTTP protocol”. We'll look briefly at web services in the section called “Web Services: The xmlrpclib Module”. We'll look at slightly lower-level protocols in the section called “Mid-Level Protocols: The urllib2 Module”. Finally, we'll show how you can use low-level sockets in the section called “Socket Programming”. Generally, you can almost always leverage an existing protocol; but it's still relatively simple to invent your own.

About TCP/IP

The essence of TCP/IP is a multi-layered view of the world. This view separates the mechanics of operating a simple Local Area Network (LAN) from the interconnection between networks, called internetworking .

The lowest level of network services are provided by mechanisms like Ethernet (see the IEEE 802.3 standards) that covers wiring between computers. The Ethernet standards include things like 10BaseT (for twisted pairs of thin wires), 10Base2 (for thicker coaxial cabling). Network services may also be wireless, using the IEEE 802.11 standards. In all cases, though, these network services provide for simple naming of devices and moving bits from device to device. These services are limited by having to know the hardware name of the receiving device; usually called the MAC address. When you buy a new network card for your computer, you change your computer's hardware name.

The TCP/IP standards put several layers of control on top of these data passing mechanisms. While these additional layers allow interconnection between networks, they also provide a standard library for using all of the various kinds of network hardware that is available. First, the Internet Protocol (IP) standard specifies addresses that are independent of the underlying hardware. The IP also breaks messages into packets and reassembles the packets in order to be independent of any network limitations on transmission lengths. The IP standard specifies how to handle errors. Additionally, the IP standard specifies how to route packets among networks, allowing packets to pass over bridges and routers between networks. Finally, IP provides a formal Network Interface Layer to divorce IP and all higher level protocols from the mechanics of the actual network.

The Transport Control Protocol (TCP) protocol relies on IP. It provides a reliable stream of bytes from one application process to another. It does this by breaking the data into packets and using IP to route those packets from source to receiver. It also uses IP to send status information and retry lost or corrupted packets. TCP keeps complete control so that the bytes that are sent are recieved exactly once and in the correct order.

Many applications, in turn, depend on the TCP/IP protocol capabilities. The Hypertext Transport Protocol (HTTP), used to view a web page, works by creating a TCP/IP connection (called a socket) between browser and web server. A request is sent from browser to web server. The web server responds to the browser request. When the web page content is complete, the socket is closed and the socket connection can be discarded.

Python provides a number of complete client protocols that are built on TCP/IP in the following modules: urllib, httplib, ftplib, gopherlib, poplib, imaplib, nntplib, smtplib, telnetlib. Each of these exploits one or more protocols in the TCP/IP family, including HTTP, FTP, GOPHER, POP, IMAP, NNTP, SMTP and Telnet. The urllib and urllib2 modules make use of multiple protocols, including HTTP and FTP, which are commonly provided by web servers.

We'll start with the high-level procotols: HTTP and how this serves web pages for people. We'll look at using this to create a web service, also. Then we'll look at lower-level protocols like FTP. Finally, we'll look at how Python deals with the low-level socket abstraction for network communications. Then we'll look at some higher-level modules that depend on sockets implicitly.

  Published under the terms of the Open Publication License Design by Interspire