EE 607 Spring 2008 Project 1
Due date: See EE 607 Spring 2008 Project
Web Page
For this assignment you will write (actually modify) C code for a
client
and server.
The server will serve files. It should be located in one of your UNIX
accounts and in its own directory. In the directory, you should also
have the following text files (these can be downloaded by clicking
them):
- file1.txt
- file2.txt
- file3.txt
The client will get a file from the server and print it out on the
terminal. If the file is not found then the client prints out a
corresponding message. The following is an example of using a client,
assuming its executable
has been renamed "getfile". Shown in red are
what
was typed in, and shown in green are the
responses from the computer.
getfile file1.txt
Aloha!
You have reached file 1.
This means that your client and server works at least partially.
Congratulations!!
Adios
getfile whoa
File "whoa" not found
Instruction
- Step 1. Read
Beej's Guide to
Network Programming
- Step 2. Modify the Simple Stream Server and Simple
Stream Client into your server and client. To test, you can use ephemeral
ports between 2000 and 5000.
- Step 3. Email me your client on the due date, before
midnight.
You should code should compile and run on spectra. Turn in
- source code
- makefile
- README file
(text), that describes how to operate your client. Include your
- Name
- EE 607, Spring 2008, Project number (e.g., Project 1)
- Date
- Instructions to compile. If you have a makefile, these
instructions could simply be, "enter makefile"
- Instructions to run the program
by tar'ing and gzipping it. tar
is a UNIX command to combine all files in a UNIX directory into a
single file. The command to tar a directory is
tar cvf Name.tar Dir
where "Dir" is the
directory to be tarred, and "Name.tar"
is the name of the new file. For all your assignments, label the
directory "YourNameProjectX", where YourName is your family name then
given name, and Project X is the current project, e.g.,
SmithTomProject1". To untar a file, enter
tar xvf Name.tar
Now, gzip is the compression algorithm for UNIX. To compress a
file, enter
gzip file
which will produce a file "file.gz". To uncompress the file, enter
gunzip file.gz
- Step 4. After you turn your client in, I will give you
instructions to run your server on spectra at a particular port number.
Run it for a couple of days in background (e.g., type "./a.out &").
Afterwards, you
can kill the job by first finding its id using ps, and then killing it
using
"kill". For more information, see the man pages of your machine.
- Note: To launch an executable program such as "a.out",
type "./a.out". The prefix "./" is what is accepted by UNIX
today. I believe it is a security upgrade.
Hints:
- Download the client.c and server.c files from Beej's Guide.
Make
sure you can compile this on specta. I was able to compile using
(note
that this was suggested in Beej's Guide under Notes for Solaris/SunOS,
but
there the example was for "cc" rather than "gcc"):
gcc client.c
-lnsl
-lsocket -lresolv
- Examine client.c and server.c. Beej's Guide explains what's
there
but basically there's two parts. First, a connection is set up
using
"connect" and "accept" . Second data is transferred using "recv"
and
"send". Note that both "recv" and "send" can be used at client
and
server to transfer strings of bytes. In the examples of client.c
and
server.c, file descripters "sockfd" and "new_fd" are used.
- For client.c, the host name of the server is given as an
argument,
argv[1].
- Many of the modifications will be using functions that do
character
string operations and opening, closing, reading, and writing to files.
If you're rusty with C then check these sites: C Programming Tutorial,
Tutorial
From Physics Dept Drexel U.. The last site is pretty good
since it has
examples.
This site has a
bunch
of links about C. For practice, write a short program that will
have
as arguments two file names and it copies the first file to the second
file.
Before copying, your program should check if the first file is
there
and the second file does not already exists, since you want to avoid
overwriting
an existing file. A string function that is useful is "strlen"
which
returns the length of a string. For IO, some of the key
operations
are fopen, fclose, fscanf, fread, getchar, and printf.
- Note that to run an executable, say "a.out", on spectra, the
command
line is "./a.out"
- Write your code in stages, starting from the original client.c
and
server.c code. Have the client send a file name to the server.
Then
have the server return the file name it received back to the client.
Then
have the server open a file and send it to the client.