Computer Networks (CSC-364 2000S)


Notes on Assignment 1: A Chat Program

These are some general notes on assignment 1.

Grading

A generally correct assignment received a B. If I felt that the overall design of your program was somewhat awkward, I gave you a B-. If I felt that there were particularly nice aspects of your program, I gave you a higher grade.

Some Notes on the Original Code

You may recall that there were a pair of lines in the original code on the order of

fgets(buf, sizeof(buf), stdin);
buf[MAX_LINE-1] = '\0';

Why do we put the 0 character at the end of the string? If there was no carriage return in the first MAX_LINE characters, there is no 0 character to terminate the string. While this won't cause a problem for send, it will cause a problem on the other side when it goes to print. Now, I'm not sure why we get sizeof(buf) characters rather than sizeof(buf)-1, but that's a problem for another day.

Common Problems

A number of you wrote something like the following

int spew(int s, char *buf, int len)
{
  while (fgets(buf, MAX_LINE, stdin)) {
    ...
  } /* while we get lines. */
} /* spew */

Sam's C Preferences

Sample Solutions

For the first solution, I put everything into one file. The way in which you run the executable determines whether it acts as a client or a server. You can find that solution as chat.c in the course examples.

For the second solution, I used separate files. chatserver.c is the server. chatclient.c is the client. chatutils.c contains the functions used by both server and client. chat.h defines shared functions and common constants.

Finally, the Makefile describes how to build everything.


History

Sunday, 13 February 2000

Monday, 14 February 2000


Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.

This page may be found at http://www.math.grin.edu/~rebelsky/Courses/CS364/2000S/Assignments/notes.01.html

Source text last modified Mon Feb 14 07:41:06 2000.

This page generated on Fri Feb 18 14:02:05 2000 by Siteweaver. Validate this page's HTML.

Contact our webmaster at rebelsky@grinnell.edu