Assignment 4: A multi-player word game Solution

$29.99 $18.99

We have provided starter code for the Makefile. Completing it is your first task and the starter code will not compile until you complete these tasks. To avoid port conflicts when testing your programs on teach.cs, you will use PORT (see below) to specify a port number. Select that number using the same algorithm we…

You’ll get a: . zip file solution

 

 

Description

Rate this product

We have provided starter code for the Makefile. Completing it is your first task and the starter code will not compile until you complete these tasks.

To avoid port conflicts when testing your programs on teach.cs, you will use PORT (see below) to specify a port number. Select that number using the same algorithm we used for lab 10: take the last four digits of your student number, and add a 5 in front. For example, if your student number is 1008123456, your port would be 53456. Using this base port, you may add 1 to it as necessary in order to use new ports (for example, the fictitious student here could also use 53457, 53458, 53459, 53460). Sometimes, when you shutdown your server (e.g. to compile and run it again), the OS will not release the old port immediately, so you may have to cycle through ports a bit.

In wordsrv.c , replace x with the port number on which the server will expect connections (this is the port based on your student number):

#ifndef PORT

#define PORT x

#endif

Then, in Makefile , replace y with your student number port plus 1:

PORT= y;

Now, if you type make PORT=53456 the program will be compiled with PORT defined as 53456 . If you type just make , PORT will be set to y as defined in the makefile. Finally, if you use gcc directly and do not use ‐D to supply a port number, it will still have the x value from your source code file. This method of setting a port value will make it possible for us to test your code by compiling with our desired port number. (Read the Makefile. It’s also useful for you to know how to use ‐D to define macros at command line.)

For assignment four, you will write a word guessing game server. The game is similar to the game you wrote in assignment two, but with some key differences. In particular, the server chooses the word before the players start guessing and doesn’t change the word during a round. The game is played by one or more players who take turns guessing letters.

Players will connect using nc . When a new player connects, the server will send them “Welcome to our word game. What is your name?”. After they input an acceptable name that is not equal to any existing player’s name and is not the empty string, they are added to the game, and all active players (if any) are alerted to the addition (e.g., “Karen has just joined.”) If they input an unacceptable name, they should be notified and asked again to enter their name.

With your server, players can join or leave the game at any time. A player leaves the game by exiting/killing

nc .

Assignment 4: A multi-player word game https://q.utoronto.ca/courses/68725/assignments/113153

Assignment 4: A multi-player word game https://q.utoronto.ca/courses/68725/assignments/113153

5页 共5 2019/3/23 14:05