CS176A - HOMEWORK ASSIGNMENT 2
Due: May 1 (By 11:59pm)
Objectives
There
are a number of objectives to this assignment. The first is to make
sure you have some experience actually doing a simple socket
programming assignment. Second, it will help you “tune up” your
programming skills and prepare you for the other upper-division
networking courses. Third, because you are allowed to use any references
you find on the Internet (including copies of existing code!),
this assignment will help you see just how many network
programming aids are available via the web. And finally, having just a
bit of practical experience will put a lot of the protocol concepts we
learn into perspective. Assignment Details
The goal of this
assignment is to implement a TCP client and server, and a UDP client
and server (for a total of four different programs). You can use either
C or Java (there will be a bit of extra credit for C since it requires
slightly more work, and more attention to detail).
Your TCP or UDP client/server will communicate over the
network and exchange data. The server will start in passive
mode listening on a specified port for a transmission from a client.
Separately, the client will be started and will contact the server on a
given IP address and port number that must be entered via the command
line.
The client should start with the string "Enter command:". It should
accept a single keypress as input. The single key should be a
"1", "2", or "3". The client should ensure that no other input is
accepted. This digit should then be sent
to the server. The server should take the following actions:
In all cases, upon receiving a response from the
server, the client should display the returned text. For the first two
commands, after receiving a response,
the client should again display: "Enter command:". In the
third case, the client should exit.
See below for the output from a sample run.
Examples
Starting the Server
Assume that you started a server on machine 128.111.49.44, listening to
port number 32000. The syntax should look like the following:
csil-machine1> server 32000
- In this example, “server” should be replaced by one of the names given below in the Assignment Turnin section.
- The server should not produce any output but should end after responding to a client string of "3".
Starting the Client
Assume that you started a client that wanted to communicate with a
server on machine 128.111.49.44, listening to
port number 32000. The syntax should look like the following:
csil-machine2> client 128.111.49.44 32000 - In this example, “client” should be replaced by one of the names given below in the Assignment Turnin section.
Client Input/Output Example
csil-machine2> client 128.111.49.44 32000
Enter command: a
Improper input.
Enter command: 1
Sat Apr 1 08:00:00 PST 2006
Enter command: 4
Improper input.
Enter command: 3
Thank You.
csil-machine2>
Language Choice and File Names
You will choose either Java or C for this assignment. In either case, you
must turn in exactly four programs (all headers, etc. should be
included in the one file). If you are using C, the programs should be:
- Client in C using UDP: client_c_udp.c
- Server in C using UDP: server_c_udp.c
- Client in C using TCP: client_c_tcp.c
- Server in C using TCP: server_c_tcp.c
To compile your C code, use the following four commands:
- "gcc -g -o client_c_udp client_c_udp.c"
- "gcc -g -o server_c_udp server_c_udp.c"
- "gcc -g -o client_c_tcp client_c_tcp.c"
- "gcc -g -o server_c_tcp server_c_tcp.c"
For Java, the program names should be:
- Client in Java using UDP: client_java_udp.java
- Server in Java using UDP: server_java_udp.java
- Client in Java using TCP: client_java_tcp.java
- Server in Java using TCP: server_java_tcp.java
To compile your Java code, use the following commands:
- "javac client_java_udp.java"
- "javac server_java_udp.java"
- "javac client_java_tcp.java"
- "javac server_java_tcp.java"
NOTE: Pay attention to all of these directions carefully. An automated
checker will be used and if there are any deviations, you will lose
points! (There is a CS176A-related point to this note as well:
as you will learn, protocols are absolutely precise, there can be no
deviation in syntax. Programming this assignment is straightforward,
but those who earn a 100 (or more) will have followed the directions
exactly.)
Grading Guidelines
You may use
pieces of code from the Internet to help you do this assignment (e.g.
basic socket code). However, this is just like citing a passage from a
book, so if you copy code, you must cite it. To do this, put a
comment at the beginning of your code that explains exactly what you
have copied, who originally wrote it, and where it came from. Below
is a breakdown of points for this assignment. In addition to
correctness, part of the points count towards how well code is written
and documented. NOTE: good code/documentation does not imply that more
is better. The goal is to be efficient, elegant and succinct!
- 20 pts: UDP client
- 20 pts: TCP client
- 20 pts: UDP server
- 20 pts: TCP server
- 20 pts: Documentation/Proper References
An assignment in C will be awarded up to 10 extra points.
Assignment Turnin
The assignment should be submitted using the course web
site. Because the web site only allows one file to be submitted, you
should use a commonly available tool (tar or zip) to combine your four files
into a single file.
Cheating Policy
This assignment is to be done individually. Cheating will not be tolerated. Please read the UCSB Academic Code of Conduct
to find out more about Student Conduct and Discipline. Of particular
relevance to this assignment is the need to properly cite material you
have used. Failure to do so constitutes plagiarism.