American Musical and Dramatic Academy Client Server Programming Project
Design a client-server application using TCP sockets, where you use the client to play a game of “Prisoner’s Dilemma” with the server.
https://ca-lti.bbcollab.com/collab/ui/session/playback/load/72496677caab4364af0a0fa7f51fcaf3
[created by Lauchlan Toal – CSCI 3171 – Summer 2020]
ASSIGNMENT TASK
Design a client-server application using TCP sockets, where you use the client to play a game of
“Prisoner’s Dilemma” with the server.
You may complete this assignment individually or in groups of 2 students. Only one
submission per group is required. You may use C/C++ or Java for this assignment; however, your
code must compile using gcc/g++ or javac on the command line.
ASSIGNMENT DETAILS:
The Prisoner’s Dilemma:
“The prisoner’s dilemma is a standard example of a game analyzed in game theory that shows
why two completely ‘rational individuals might not cooperate, even if it appears that it is in their
best interests to do so”.1
It is presented as follows:
“Two members of a criminal gang are arrested and imprisoned. Each prisoner is in
solitary confinement with no means of communicating with the other. The
prosecutors lack sufficient evidence to convict the pair on the principal charge. They
hope to get both sentenced to a year in prison on a lesser charge. Simultaneously,
the prosecutors offer each prisoner a bargain. Each prisoner is given the opportunity
either to: betray the other by testifying that the other committed the crime, or to
cooperate with the other by remaining silent. The offer is:
• If A and Beach betray the other, each of them serves 2 years in prison
• If A betrays B but B remains silent, A will be set free and B will serve 3 years
in prison (and vice versa)
• If A and B both remain silent, both will only serve 1 year in prison (on the
lesser charge)”
This is summarized in the figure on the right. The following
Prisoner A
YouTube video also explains Prisoner’s Dilemma (you only
Silent Betray
need to watch up to 1:50 minutes of this video):
-1
0
https://www.youtube.com/watch?v=t9L02 FgxWHw
Silent
-1
-3
Your Task:
you will write simple client-server application(s) in which the
client acts as prisoner A and the server acts as prisoner B. The
protocol between the client and server should be as follows:
• The server program is started on a user-defined port.
Prisoner B
-3
-2
Betray
0
-2
https://en.wikipedia.org/wiki/Prisoner%27s dilemma).
The client program is started and connects to the server using the server IP and port
number provided on the command line.
• The client asks the user for input. The input may either be Silent or Betray. Any other input
should result in an error message, asking the user to try again.
• The user’s input is sent to the server via the connected socket
• The server (acting as prisoner B) may decide to remain Silent or Betray. How the server
decides is completely up to you. For fairness, you may use a random approach.
• The server reads the user’s input from the client socket, evaluates the outcome (years in
prison for both Prisoner A (i.e., client), and Prisoner B (i.e., server)), displays each prisoners’
choice and resulting sentences (Freedom, 1 year in prison, 2 years in prison or 3 years
in prison), and sends this information (i.e., Server’s choice and the resulting prison
sentences for both prisoners) back to the client
• The client should display the server’s reply (i.e., Server’s choice and the resulting sentences)
to the user.
• The client should give the user an option to try again or quit
Socket Programming:
If you haven’t already done so, please follow the TCP/IP server programming Lab recording (video
link available in Lab 5 on Brightspace) and also go through the basicserver.c file posted in Content-
>Labs->Lab 5 zip file on Brightspace.
In addition, explore the following commands in C that may be helpful for you in creating client and
server programs in C:
socket (…), inet_pton (…), htons (…), connect (…), send (…), recv(…),
close (…), read(), write(), struct sockaddr_in, bind (…), listen (…),
accept (…), inet_ntop(…)
Following are some helpful tutorials on socket programming using TCP including code samples.
Feel free to study and understand any or all of these before starting on your assignment.
• http://www.linuxhowtos.org/C_C++/socket.htm
• https://www.codeproject.com/Articles/586000/Networking-and-Socket-programming.
tutorial-in-C
http://www.csd.uoc.gr/~hy556/material/tutorials/cs556-3rd-tutorial.pdf
Note: Above references are for understanding how socket programming works. You are not
allowed to copy any code from external sources.
SUBMISSION DETAILS:
This assignment can be done individually, or in groups of 2. In case of groups, only one submission
per group is required.
Upload a single zip file containing:
1. A “code” folder containing your code,
2. an image file (.jpg or.png) showing a screen capture of your client and server programs in
action, and
3. a readme.txt file containing
i.
instructions to compile and run your program including the compilation string (and the
execution string if applicable).
ii. names of the group members and specific contribution by each team member (if group
of 2)
to the Assignment 3 dropbox on Brightspace. Do NOT submit the executable.
SUBMISSION DEADLINE:
Monday, 28-March-2022, 11:59PM
GRADING CRITERIA:
• Code for both the client and the server compiles using the instructions provided in your
readme.txt file. Assignment instructions are properly followed. (Note that you may decide to
build a single app with an option to run it as either a client or a server.)
You may get a zero in this assignment if your code does not compile with gcc/g++
or javac as per your provided instructions.
Also note that marks may be deducted for any warnings generated during compilation.
Marks Distribution:
• Server program can be started (2) on a user-defined port (1).
• Client program can be started and connects to server using either local host (2) or an IP
address (2) and port number (1) provided on the command line.
• Client asks user for input (1). Error checking is done for user input and User can try again
without exiting the program (1).
• User input is transmitted to the server (1)
Server reads client’s choice and echoes on server output (1)
Server chooses a response (random or fixed) and displays on server output (1)
• Server evaluates the outcome (Freedom, 1 year in prison, 2 years in prison or 3 years in prison)
based on client’s message and server’s choice and echoes on server output (1)
• Server sends server response and outcome of the game to the client (1)
Client receives response (1) and displays it on the client’s output (1)
Client gives the user an option to replay the game or quit (1)
• readme.txt file provided with group member contributions (if applicable) and correct compile
string (2)
[Note: You do not need to write a multi-threaded server. Connecting a single client at a time is enough
Top-quality papers guaranteed
100% original papers
We sell only unique pieces of writing completed according to your demands.
Confidential service
We use security encryption to keep your personal data protected.
Money-back guarantee
We can give your money back if something goes wrong with your order.
Enjoy the free features we offer to everyone
-
Title page
Get a free title page formatted according to the specifics of your particular style.
-
Custom formatting
Request us to use APA, MLA, Harvard, Chicago, or any other style for your essay.
-
Bibliography page
Don’t pay extra for a list of references that perfectly fits your academic needs.
-
24/7 support assistance
Ask us a question anytime you need to—we don’t charge extra for supporting you!
Calculate how much your essay costs
What we are popular for
- English 101
- History
- Business Studies
- Management
- Literature
- Composition
- Psychology
- Philosophy
- Marketing
- Economics