M.I.T. DEPARTMENT OF EECS

6.033 - Computer System Engineering X Windows Hands-On Assignment

Hands-on 2: X Windows

Having read the sections of the X Window System paper assigned for Recitation 6, complete the following hands-on assignment. You should do the activities described below, answer (only!) the numbered questions, and hand in your answers at the beginning of class on Thursday, February 17.

The purpose of this assignment is to give you some hands-on experience playing with the details of the X Window system. In particular, by the end of the assignment, you should have a good understanding of how to use X and how X manages complexity using modularity (through the client-server architecture).

This assignment should take one to two hours at most. Please turn in answers to the questions asked only! Do not submit pages of output from the various commands. Also include how long this assignment took you to complete so we can gauge the complexity of future assignments. Because students start 6.033 with widely varying levels of experience, this assignment goes into considerably more detail than later assignments will, when everyone is up to speed on using Unix and Athena.

0. Setup

To do this lab, you'll need to use the program xmond. We have compiled and installed xmond in the 6.033 locker on Athena, which can be accessed by typing add 6.033 at an athena% prompt. Athena's add command sets your environment up so you can run compiled programs by name out of a locker. (The 6.033 locker is a directory named /mit/6.033 that is stored on a central Athena server.)

We strongly encourage you to do this assignment physically sitting in front of an Athena workstation. You may run into X authentication if you try to run remotely.

I. Warmup: Basic X usage

The design of X has led it to be highly configurable and customizable. To begin understanding some of this, skim the generic man page for the X window system:

athena% man X
Create an xlogo (command: xlogo) with a different background and foreground color from the default. Make it 300 by 300 pixels in size and start out in the top right corner.

Question 1: What arguments did you pass to xlogo?

II. Understanding the client-server protocol

Now, let's get our hands dirty playing with some of the more technical parts of X. Section 3 of the X Windows paper discusses the network protocol that X clients and servers use to communicate. We'll use xmond to examine the content of a conversation between a simple X client and the X server running on your machine.

Before running this tool, consider how it works. To intercept communication between an X client and an X server the tool acts as a proxy. A proxy acts as a forwarder: it accepts requests from a number of clients (possibly modifying them) and forwards them to a server. A common type of proxy you may have used is a caching Web proxy which accepts Web page requests and attempts to fulfill them from a local store of pages, before fetching the page from a remote server.

Question 2: Describe where an X proxy most logically fits into the box-and-lines diagram, Figure 1 from the X Windows paper. There are multiple possibilities: describe briefly how the modification you describe would work and why you think it's the best solution. List the changes that such a proxy would require in the client code, server code, and user environment. (Some of these may not have to be modified.)

Question 3: From the perspective of an X client (like xlogo), is the proxy a server or a client? What about from the perspective of your X server?

III. Running xmond

We'll need two xterms to make all of this work. An xterm is a terminal emulator for X; it's a place to type commands and see their results. To launch an xterm, type the following at an athena prompt:

athena% xterm &
The xterm part means to run the program named "xterm". Normally, the shell (the program that prints the athena% prompt and accepts your commands) would wait until the xterm exits before performing your next command. However, the ampersand at the end of your command tells the shell to go ahead and accept new commands without waiting. That is, the shell runs the first command asynchronously, a concept that we've seen in lecture and will see again in a different context in section IV, below.

Start two fresh xterms, which we'll call "left" and "right". In "left", run the following:

athena% xhost +localhost
localhost being added to access control list
athena% add 6.033
athena% xmond -server localhost:0 -port 20 -verbose 4
The xhost command allows unauthorized clients (such as the proxy) to connect, but only from the same host; normally such connections would be rejected.

The xmond command starts up the proxy, which won't produce any output until it receives an incoming connection. (You shouldn't expect the command prompt to come back in the xterm until you quit the xmond program by typing "quit" followed by the enter key.) The -verbose 4 flag tells the proxy to print every message it sees in great detail. You can tune exactly what is printed by interacting with the proxy. For instance, typing "event_verbose 0" into "left" while xmond is running will instruct the proxy not to print information about X events. Type "help" to get a full list of commands that xmond supports. The port 20 flag tells xmond what to name the ("fake") server it sets up. In this example, xmond is acting as a server for a display identified as localhost:20.

Now we'll generate some events for xmond to print. In "right", type the following:

athena% xlogo -display localhost:20 &
This command runs an xlogo which connects to xmond instead of to your real X server. After you run xlogo, you should see a trace of the messages it is sending to the X server in "left". Here is a snippet from what that trace might look like:
 ............REQUEST: FillPoly 
             sequence number: 0026 
              request length: 0008
                    drawable: DWB 06c00004
                          gc: GXC 06c00003
                       shape: Convex
             coordinate-mode: Origin
                      points: (4)
                                   x: 91
                                   y: 0
                ---
                                   x: 88
                                   y: 0
                ---
                                   x: 9
                                   y: 100
                ---
                                   x: 12
                                   y: 100
                ---
All requests have a sequence number which identifies them and allows the client to match replies with requests. This particular command draws a polygon, and the request contains the coordinates of the polygon. The request was generated by a subroutine named "XFillPolygon". For further information about XFillPolygon and other common X drawing commands, see the XFree86 documentation. By examining the coordinates, we can guess that this command draws the top-left to bottom-right stroke of the X in the logo.

IV. Examining the trace

In the second paragraph of page 87 in the X Windows paper, the authors say that they chose to use an asynchronous communication system. That means that, after a request is issued, the client is able to send other requests without waiting for a reply from the server, just as the ampersand to the UNIX shell allowed you to start other commands without waiting for the first one to terminate.

Question 4: Look at the trace from the xlogo startup and find an example of a request for which no reply is necessary and one for which a reply is received by the client. Choose a request which is not an X event (events are marked with the EVENT tag in the trace). Can you generalize about what sort of commands do not require a reply?

It may be helpful to redirect the output of xmon to a file to answer this question. Try something like:

athena% xmond -server localhost:0 -port 20 -verbose 4 > trace.out
You can now open trace.out in your favorite text editor. (For example, emacs trace.out .)

V. Fun with xmond

Now we'll see how well you understand the request/reply stream. Set up xmond as before, and instead of running the "stock" xlogo, run our modified version xlogo-6.033 in the 6.033 locker. You'll type this into "right":

athena% add 6.033
athena% xlogo-6.033 -display localhost:20 &
We've changed this xlogo to draw a hidden text string to the X server; that is, the client will issue the XDrawString call to draw the string, but you won't see any text on the screen. By examining the trace, you should be able to find this string.

Question 5: What is the string that the modified xlogo draws? (You may not open the binary or run 'strings' or 'grep' or similar commands on the binary to answer this question.) Include the portion of the trace that helped you answer this question (and nothing more).

Question 6: How long did it take you to do this assignment?


Go to 6.033 Home Page