M.I.T. DEPARTMENT OF EECS

6.033 - Computer System Engineering X-Windows Hands-On Assignment

Hands-on 1: X-Windows

This hands-on assignment is due at the beginning of class Thursday Feb 13.

Read the paper on the X Window system (reading #4) and complete the following hands-on assignment.

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.

0. Setup

To do this lab you'll need to use the xmon software which I have compiled and installed in the 033 locker. The software is only compiled for linux machines. To do this lab find a linux athena machine in the clusters. You can spot a linux machine by the word "Dell" written on the case. Once you log in type "uname -a" and look for the word "Linux" in the output to make sure.

If you want to do the lab on your own (non-linux) machine you can build the xmon package from source. The sources can be found at /mit/6.033/software/xmon.1.5.4.tar.gz.

I. Warmup: Basic X usage

The design of X has led it to be highly configurable and customizable. To begin understanding some of this complete the following task: Create an xlogo (command: xlogo) with a different background and foreground color from the default, that is 500x500 pixels in size and starts out in the bottom right corner. The man pages for X and xlogo may be helpful:

athena% man X
athena% man xlogo

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 will be using a tool to examine the content of a conversation between a simple X client and the X server running on your machine.

Before we run 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 clients (possibly modifies them) and forwards them to a server. A common proxy you may have used is a caching web proxy which accepts page requests and attempts to fulfill them from a local cache of pages before fetching the page from a remote server.

Answer the following questions about the X proxy we'll use in this assignment:

Question 2: Describe where an X proxy most logically fits into the Figure 1 from the X windows paper. There are multiple possibilities: describe briefly how the one you describe works and why you think it's the best possibility. Things to think about are how many changes are required to the client code, server code and user environment.

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 xmon

The tool we'll use to dump protocol messages is called "xmon." You can run it straight out of the 033 locker. We'll need a couple of xterms to make all of this work. Get two fresh xterms which we'll call "left" and "right". In left do the following. Material in green is what you'll input.
athena% add 6.033
athena% xhost +
access control disabled, clients can connect from any host
athena% /mit/6.033/software/xmond -port 20 -verbose 4
The above commands disable access control so that the debugging proxy can connect to your X server and start up the proxy (xmond). The verbose 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 to not print out information about X events. Type "help" to get a full list of commands that xmond supports. The port flag tells xmond what X display it should proxy: in this example xmond is acting as a server for display (in X notation) localhost:20.

Now we'll generate some events for xmond to print out. In right do the following:

athena% setenv DISPLAY localhost:20
athena% xlogo
^C (note: this means hold down control and hit C)
These commands first set your DISPLAY variable to the screen served by the proxy and then run a simple xclient (xlogo). After you run xlogo you should see a trace of the messages it is sending to the xserver in left. Here is a snippet from what that trace might look something 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 the "XFillPoly" command which you can read about at the XFree86 documentation site along with the other common X drawing commands. 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 is, after a request is issued the client is able to send other requests without waiting for a reply from the server.

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 since it may not fit in your xterm scrollback buffer. Try something like:

athena% add 6.033
athena% xhost +
access control disabled, clients can connect from any host
athena% /mit/6.033/software/xmond -port 20 -verbose 4 > trace.out
You can now open out.trace in your favorite text editor.

V. Fun with xmond

Now we'll see how well you understand the request/reply stream. Setup xmond as before and instead of running the "stock" xlogo, run the xlogo in /mit/6.033/software. You'll type this into right:
athena% setenv DISPLAY localhost:20
athena% /mit/6.033/software/xlogo
^C (note: this means hold down control and hit C)
This xlogo is slightly modified to draw a hidden text string (i.e. 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).


Go to 6.033 Home Page Questions or Comments: 6.033-tas@mit.edu