Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact
Version 18 (modified by JJR, 13 years ago)
fix

Leave Comments, Critiques, and Suggestions Here?

An Introduction to Networking with Tango

Here we discuss the network components provided by the Tango API. Anyone with even a vague recollection of the old C socket interfaces will recall why network software development has always been such a "trial by ordeal". It is just not fun working with cryptic API's, seemingly inconsistant conventions, and confusing preprocessor macros. Tango, of course, really tries to make it all easier. The approach, once again, is to make the network API clear and consistant across platforms.

While claiming an API to be easy does not make it so, we hope the examples and explanations in this chapter will be adequate testimony that Tango "gets it right." The Tango network interface is foundational to many powerful and more complex network objects which will be discussed later.

First, however, let us present a little history of networking. This should give a background as to why fundamental entities like sockets, ports, and internet addresses exist in the first place.

A Brief History of Networking

In the early days of UNIX (circa 1977), it was Berkley Software Distribution's UNIX that made some critical contributions to the field of network API's. BSD UNIX (as the academic-born UNIX operating system came to be called) was a direct competitor with AT&T Bell Lab's UNIX distribution. Bell Lab's UNIX was the original design for what became the most popular OS model of the last half a century. Both UNIX designs eventually contributed important network protocols and interfaces that are in common use today. The Internet is the most obvious example of the UNIX influence.

Already a luminary in business and academics, BSD UNIX exploded in popularity when Sun released its own derivative called SunOS. Unfortunately, this only widened the divergence of the two UNIX styles -- BSD and Bell Lab's -- which were distinctly incompatible for a number of years. However, later versions of these two operating systems shared more in common, significantly blurring the line between the two systems: specifically, Bell Lab's final major release, called System V, merged features and tools from the ever popular BSD UNIX. Nevertheless, the shared features made the two operating systems more independently useful but did little to improve cross-compatibility. (citation)

While in the process of enriching the distribution, BSD managed to invent several innovative programming interfaces. In the network programming sector, one of the most important of these became known as "BSD Sockets." In short order, BSD Sockets was practically a standard across many UNIX-derivative distributions. The socket concept was the high level rendition of network communication. Years later, sockets have become a defacto standard in practically every modern operating system.

A Summary of Networking

Simply, a network is a collection of computers that communicate with each other through a transmission medium. The communication mechanism must be managed like any other resource to prevent complete pandemonium amongst the connected computers, much like a group of children must be made to talk in turn in order for their speech to be intelligible. Even so, communication is usually managed on several levels using hardware and software protocols. Some protocols help prioritize transmissions; others route the communication to the correct computer; still others help guarantee that connections are established and maintained between specific points.

These protocols are rules that state how network components agree to communicate. They are integrated into hardware or software and are present in multiple levels of any network model.

Networks were coming into such prominence that eventually a standard model was designed to describe how to connect combinations of devices for communication. (Complete Encyclopedia of Networking, p 727). The Open Systems Interconnection (OSI Reference Model) is a seven-layer model meant to demonstrate the functional layers of a network and the features available in each layer. (REWORD LAST SENTENCE COMPLETELY)

A layer represents a functional contributer to a portion of the network model. For example, a software application with its protocols represents the highest level Application Layer of the OSI (FTP and Telnet are application layer protocols); TCP and UDP protocols represent a middle layer called the Transport Layer; and the transmission line (wired or wireless) represents the the lowest layer called the Physical Layer. (Ibid. p 734) See the figure for a full view of the seven layer model.

The OSI model acts as a guideline only, an abstract breakdown of how network systems operate. Most networks systems will implement most of these layers, but they won't be so clearly defined. Some layers may be logically merged for convenience.

What the OSI model should indicate is that communication happens in layers. The model helps us understand how network systems work: when we make a connection with another computer, there are several processes that go on, each playing an important part in carrying the payload (the packet) to the destination. Each level generates overhead in carrying the payload; this overhead is the price paid by the delivery system in exchange for reliability and functionality.

Each layer at the destination sees its equivalent layer at the source. This means that packets are passed down the layers at the source and back up the layers at the destination; the destination levels strip off the pertinent information designated for their specific layer until the packet is presented in its naked form to the Application Layer. This process will be useful to understand when we discuss the Tango Socket in the next section.

tango.net.Socket

Like the name implies, a socket is a medium for connecting one entity to another. The entities involved are always processes (software running on an operating system) that may exist on local or distributed network nodes (computers). Each process must create a socket in order to establish a communication portal. From the application perspective, the location of the communicating nodes is unimportant so long as the nodes are members of an operational network. Since the socket interface facilitates a form of distributed communication, the mechanism is often referred to as interprocess communication (IPC).

Data that is sent or received in this model is called a packet. A packet contains useful information that one processes delivers to another. Examples of packets would be anything from emails sent out on the Internet to web pages being downloaded from a server. Though packets may be almost any size, practicality dictates that information transferred must be broken up into smaller parts before transmission. While the application may see the received web page as a whole, lower level layers will usually partition large payloads into smaller. These packets are sections of the whole transmitted in designated byte sizes.

In Tango the Socket class constitutes a complete wrapper for the BSD Socket API. In that sense, it is a low level network interface in Tango: despite simplifying the interface of the BSD Socket in general, using it still requires a thorough knowledge of the BSD mechanism. Here we will give an overview of how to apply the Tango Socket mechanism. For a more thorough discussion of network socket specifics, see the references at the end of this chapter. In later sections, this chapter will introduce high level network interfaces that eliminate much of the hassle of working with low-level sockets.

More than Sockets

Tango exposes this kind of low-level access via tango.net.Socket, but that is just too low-lowel for general usage. Thus, Tango provides a number of higher level wrappers to make Internet programming more productive.

TO BE WRITTEN:

SocketConduit?

ServerSocket?

DatagramConduit?

MulticastConduit?

Graphs

This is the internet equivalent of FileConduit:

source:/trunk/doc/images/SocketConduit.gif

References

A history: http://www.coe.berkeley.edu/labnotes/history_unix.html

An excellent guide to low-level socket programming is right here