Sockets for this problem you will implement a client-server

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

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: EM13346580

Questions Cloud

1 a firm estimates its cubic production function of the : 1. a firm estimates its cubic production function of the following formq al3 bl2and obtains the following
Marketing research project project that required to plan : marketing research project project that required to plan and strategize effectively. if you use your time efficiently.
There are two more unit-sphere les given in : there are two more unit-sphere ?les given in httpcis.poly.educs653assg3 with 256 and 1024 triangles respectively.draw
1briefly describe venture debt capital and venture equity : 1.briefly describe venture debt capital and venture equity capital.2.describe how the costs of debt and equity differ
Sockets for this problem you will implement a client-server : sockets for this problem you will implement a client-server version of the rock-paper-scissors-lizard-spock game which
Question 1assume a manufacturer incurs 2000000 hours of : question 1assume a manufacturer incurs 2000000 hours of direct productive labor in a year at a total direct labor cost
1nbsp find the natural domain of the following functions : 1.nbsp find the natural domain of the following functions. explain your results.2. given the equation y x2 - 6x 8 find
Product and engineering design review8 x product : product and engineering design review8 x product engineering and design review week 2 ndash 12 3 pages per item which
Add drop down lists for modifying the different style : add drop down lists for modifying the different style elements for the label element that displays the time.we will do

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Reads from the external file input.txt

Program that reads from the external file input.txt, counts the letters in every word, replaces the word by that number, and then writes the numbers to an external file output.tx

  Write a program to read a data file and extract parameters

Write a C/C++ program to read a data file and extract parameters. The program must obtain the filename via a command-line argument.

  Object oriented programming paradigm is better choice

Explain why object oriented programming paradigm is considered better choice than structured programming paradigm. Does it reflect our "natural" way of thinking or do you find it artificial?

  Design your application according to the considerations

Design your application according to the considerations described above.  For example, you must use functions that have the specified signatures, and arrays that have the specified declarations. They are

  Design a simple atm service kiosk

Design a simple ATM service kiosk. This kiosk supports the following options for its menu: 1. Viewing your account balance2. Depositing cash3. Withdrawing cash

  Atm system code two classes with related attributes

Related to ATM system code two classes with realted attributes and operations!in C++

  Write a program that prompts the user to input

One metric ton is approximately 2205 pounds. Write a program that prompts the user to input the amount of rice, in pounds, in a bag. The program outputs the number of bags needed to store one.

  Takes a string containing a full name

Write a program that takes a string containing a full name and outputs each part of the name separately with its length. The name should be in the form of first, middle, and last name, separated from each other by a single space. For example, if the ..

  Write a single statement that prints a number

Write a single statement (in C++ language) that prints a number at random from each of the following set.

  Write a function named dietoss that simulates the tossing

Write a function named dieToss that simulates the tossing of two dice. When you call the function, it should generate two random numbers ranged in 1 to 6 and return the sum of the die's numbers. In the mail program, ask user how many times the dice s..

  Define a class that consists of three objects

Define a class that consists of three objects: day, month, and year. Within this class define two member function (constructor ) to initialize the objects to today?s date and one that display the date as follows: 05/7/2002

  Gcd between two positive integer numbers

Write a C++ code for calculating the GCD (Greatest Common Divisor) between two positive integer numbers. You  should  use Euclid's  original  subtraction  based  GCD algorithm ( not  using  modulo operator). You should write a function following t..

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