CS176A - HOMEWORK ASSIGNMENT 2
Due: April 25 (By 11:59pm)
Objective
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 can use the Internet to look for
examples, 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
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. 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 will pass the server a string consisting of a sequence
of characters. If the the string contains anything but numbers, the
server will respond with "Sorry, cannot compute!" and exit. If the
string contains all numbers, the individual digits will be added
together and returned as a string (see below for an example). If the
server sends a "Sorry" response to the client it will immediately exit.
If the server receives a string of numbers, it will (1) add the digits
together, (2) send the value back to the client, and (3) will not exit
unless the response is a single digit. This process will be repeated
until there is only one digit remaining. See below for the exact
output.
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 Submission section.
- The server should not produce any output but should end after interacting with a client.
Starting the Client
csil-machine2> client 128.111.49.44 32000 - In this example, “client” should be replaced by one of the names given below in the Submission section.
Client Input/Output for Non-Numeric Example
csil-machine2> client 128.111.49.44 32000
Enter string: I don't like addition!!
From server: Sorry, cannot compute!
csil-machine2>
Client Input/Output for Numeric Example
csil-machine2> client 128.111.49.44 32000
Enter string: 123456789101234567891012345678910
From server: 138
From server: 12
From server: 3
csil-machine2>
Submission
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: - Server in C using UDP (file name to turn in: server_c_udp.c)
- Client in C using UDP (file name to turn in: client_c_udp.c)
- Server in C using TCP (file name to turn in: server_c_tcp.c)
- Client in C using TCP (file name to turn in: client_c_tcp.c)
To compile your C code, use the following two commands:
"gcc -g -o client_c_udp client_c_udp.c" and
"gcc -g -o server_c_udp server_c_udp.c" For Java, the program names should be:
- Server in Java using UDP (file name to turn in: server_java_udp.java)
- Client in Java using UDP (file name to turn in: client_java_udp.java)
- Server in Java using TCP (file name to turn in: server_java_tcp.java)
- Client in Java using TCP (file name to turn in: client_java_tcp.java)
To compile your Java code, use the following commands:
"javac server_java_udp.java"
"javac client_java_udp.java"
"javac server_java_tcp.java"
"javac client_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!
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 (tar or zip) to combine your four files
into a single file.
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
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.