What does all this stuff about "client-server" mean ?

Everybody says that X has a "client-server" architecture. So this must be true, but what does it mean ?

Well, basically a client-server architecture is conceptually a simple thing, but the consequences may be a bit subtle, especially the way it is implemented in the Xlib.

What is a client-server architecture ?

A client-server architecture is a general mechanism for handling a shared resource that several programs may want to access simultaneously. In the case of X, the shared resources are the drawing area and the input channel. If every process was allowed to write on it at its will, several processes may want to draw at the same place, resulting in an unpredictable chaos. Thus, only one process is allowed to get access to the drawing area: the X server. The processes wanting to draw stuff or get inputs send requests to the X servers (they are "clients"). They do this over a communication channel. The X server performs the requests for its clients, and sends them back replies. It may also send messages without explicit client's requests to keep them informed of what is going on. These messages sent by the server on its own behalf are called "events".

Advantages of the client-server architecture

The client-server architecture has several advantages, many of them resulting from the ability to run the server and the clients on separate machines. Here are some advantages:

Structure of the X client-server architecture

As we already mentioned, the server and a client communicates over a communication channel. This channel is composed of two layers: the low-level one, which is responsible for carrying bytes in a reliable way (that is with no loss nor duplication). This link may be among others a named pipe in the Unix environment, a DECNet link and of course a TCP/IP connection.

The upper layer use the byte-transport channel to implement a higher-level protocol: the X protocol. This protocol says how to tell the server to request window creation, graphics drawing, and so on, and how the server answers and sends events. The protocol itself is separated into different parts:

[to be continued].
Christophe Tronche, ch@tronche.com