CSE342 - Lab 11: Client-Server Protocol

PURPOSE: Add keyboard input and client->server protocol to your semester project.

EXERCISE: To add keyboard input processing to your client, you'll need to use select(3c) system function.

The select() system call allows a program to wait for activity on several file descriptors (including sockets) simultaneously. Review the manual page for select(). To help make sense out of the manual page, consider the following code fragment:

        #include <sys/time.h>
        #include <sys/types.h>
        #include <unistd.h>

        fd_set readfds;
        int fd;

        FD_ZERO(&readfds);
        FD_SET(fd, &readfds); /* Watch for input from server */
        FD_SET(0, &readfds);  /* Watch for input from kbd */

        i = select(getdtablesize(), &readfds, 0, 0, 0);

        if (FD_ISSET(0,  &readfds)) /* kbd input available */
        if (FD_ISSET(fd, &readfds)) /* file input available */
Your client will need to use select on the socket with the connection to the server and on stdin.

You will also need to add initialization code to your client to disable input line processing and echoing. The code for this initialization is described in the final project notes.

The client->server protocol is also described in the fourth project outline. For each command to the server, send a single byte containing the number of the command (e.g., 16 to rotate left).

By the time you've finished this lab, your client should map user keystrokes into commands to the server. You can monitor the operation of your client by watching its behavior through the use of the sample robowar-client program that you used previously.


Last modified 8 November 2007.