Iimplement a client-server of the game

Assignment Help C/C++ Programming
Reference no: EM13472

Sockets: For this problem you will implement a client-server version of the rock-paper-scissors-lizard-Spock game, which we will refer to as rpsls.

The game server, which you will implement in server.c, will moderate one or more games of rpsls between two clients, which you will implement in client.c. Three processes will be running when a game is being played (the server and two instances of the client).

server.c: The server moderates zero or more games between two players (client processes). The server will create two stream sockets with two different port numbers (60000 and 60001, for example) and waits for requests to play a game from two clients. Once a connection has been made with two clients, the server sends a message to both players informing each of the two players names and asking for their hand gestures (one of rock, paper, scissors, lizard or Spock) for a game of rpsls; it then waits for each to send their gesture. Once both players send their gesture, the server decides who wins and informs both players who won that round and asks for their gestures for the next round. The game is repeated until one (or both) players wishes to stop playing. When no more games are to be played the server sends, to both players, the game statistics and then the server closes both sockets.

client.c: A client creates a socket and tries to connect to the server. If it is unable to connect to the first port (perhaps the other client is already connected to that port) it tries with the second port number of the server. When a connection is made with the server, the client should send the player's name to the server (the client should ask the user for their at some point when it first runs). When asked for a gesture for a game, the client queries the user (to input a gesture from stdin) and then sends the gesture to the server.

This is repeated until either the player wishes to stop playing (or the other player wishes to stop playing). When the server send the game statistics, the client displays the information to the user (stdout), closes its socket and terminates.

Here are some details for the implementation:

o server: the server will optionally accept a command line argument that will act as a shift for the port numbers to use. If no command line argument is given, it will try to use ports 60000 and 60001. If a command line argument is given, it will be an integer (call it n) and the sever will try to use ports 60000+n and 60001+n.

o client: the client will use one or two command line arguments. The first argument (not including the program name) will be the IP address of the server. The second, optional, argument will be the same number that was used when running the server (if one was provided) to specify which ports to try.

o client: after initially sending the player's name to the server, the client will only ever send one of 6 messages (for each game) to the server: rock, paper, scissors, lizard, Spock, or end.

o server: when the server receives end as a gesture from one of the players, it sends the game statistics to the players. That is, it sends the total number of games and how many each player has won.

o client: if the player enters bad data, it will ask the player to try again and enter something proper. It will not send bad data to the server.

o server: the server will have no output (to stdout or stderr) during its execution.

o client: when the client displays who won the previous game (using the information sent from the server), it should display a user-friendly message to stdout (for the player to read) and it should also a terse message to stderr. The message fro stderr should simply be the word "win" or "lose", followed by a newlines. Each client should send the appropriate message to stderr (depending if their player won or lost).

Create an appropriate Makefile for your server.c and client.c programs. Your output to stdout during game play should be minimal
Add your server.c, client.c and Makefile files to your tar file. (Both your server and client programs need to have a main() function.)
Note: In class I mentioned that we would implement tic-tac-toe. The game itself will be more complex to implement, so I went with this more straightforward game. For those that are disappointed, perhaps this xkcd comic will be some consolation.

2. Processes and Signals: Implement a guessing game. When your program begins, it should fork into two processes: parent and child. The child process will interact with the user via stdin and stdout. It first prompts the user for a secret number between 0 and 1023 (inclusive). The parent process will try to guess the user's number by randomly picking a number between 0 and 1023 and displaying it to stdout. The user will then enter either "hi" or "lo", depending if the parent's guess is either too high or too low, respectively, compared to the secret that the child process knows (which it input from the user). The child will then send either SIGUSR1 or SIGUSR2 to the parent process to let it know if its guess is too high or too low, respectively. The parent then guesses a new number and everything repeates until the parent guesses the secret number. At this point, the user will enter "correct" and the child will send a SIGINT signal to the parent to indicate it has guessed correctly. The parent then displays the number of guesses it needed to guess the correct number and then sends a SIGINT signal to the child. When the child recives the SIGINT, it kills the parent process and then terminates itself.

Implement your program in guess.c. In your code, include some debugging print statements. Each time a process send a signal, it should also print a string to stderr with the format

senderPID # signal-name # receiverPID

where senderPID is the pid of the sending process, receiverPID is the pid of the receiving process, and signal-name is the name of the signal being sent.

Add your guess.c and Makefile files to your tar file. Your Makefile should generate the executable guess.

Libraries: You will create a very basic encryption/decryption library, called libcrypto.a.

For this question, you will need to submit the following files:

o encrypt.h (start with this)
o encrypt.c
o decrypt.h (start with this)
o decrypt.c
o main.c (start with this example)
o Makefile

You will need to implement the given functions in the header files in the associated .c files. Your main.c will test your encrypt and decrypt functions. Notice that if you encrypt something with a shift of N and then descrypt with the same N, you should recover the original string.

Your makefile should have the following targets:

o main : generates an executabe for the main.c (do not link any .o files; this musy use your crypto library).
o encrypt.o
o decrypt.o
o library : creates the crypto library using the ar program
o clean : removes all .o files and executables

Add all of the above files to your tar file.

Reference no: EM13472

Questions Cloud

Production and cost estimation : Do the estimated coefficients have the required signs to yield a-shaped AVC curve? Discuss the significance using the p-values.
Marketing research project : Project that required to plan and strategize effectively. If you use your time efficiently. You are to create a report that analyzes marketing research conducted by you for any company.
Shadow effect while rolling a sphere : Shadow effect while rolling a sphere as well as the options of shading and lighting.
Describe venture debt capital and venture equity capital : Describe venture debt capital and venture equity capital.
Iimplement a client-server of the game : Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.
What is the average direct labor cost rate : What is the average direct labor cost rate and What is the overhead rate.
Find the natural domain : Find the natural domain of the given functions.
Advanced design methodologies : 8 x product engineering and design review (week 2 – 12), ~3 pages per item which must contain a brief description of the product then delve into concepts such as materials selection, manufacturing methods, life cycle analysis, recyclability and overa..
Business strategy and strategic human resource management : This project report describes the co-ordination and alignment of business strategy with strategic human resource management.


Write a Review


C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd