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

  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 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.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

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