Weight: 10% of course grade.
Due date: 10:00 p.m. Friday August 11
In this assignment, you will be writing a simple client-server casino system. You will be writing two C programs, one server and one client, that implement a basic protocol allowing multiple users to play blackjack over the Internet. The rules for blackjack (including our simplifications) are explained in the assignment 3 specifications.
Your server will be called bjserver. It will act as a blackjack dealer, dealing a game of blackjack for up to 6 currently connected players.
Your program should support being run in the following manner:
$ bjserver [numdecks]
The optional numdecks indicates the number of decks to use in the game, and must be between 1 and 8 inclusive. You should default to using 6 decks if the numdecks parameter is absent.
Your program will listen on the specified port for client connections, and while clients are connected, your server will deal rounds of blackjack, using messages according to the protocol below. Each message that is expressed as a string is terminated with a null '\0' character.
Once a client connects, the client may join play in the next round. Play proceeds according to the rules established in the Assignment 3 specification: in particular, cards are shuffled between rounds when there is less than one deck remaining to play with, no splitting or double-downs, blackjacks are paid out at 3:2 odds rounded down ot an integer. The following protocol indicates the comminication between the server and the clients during each round of play.
Normally hands are played sequentially. Over the Internet, though, network delays might slow the play, and one slow player would make the other players impatient. To speed play, the server should allow players to play their hands in parallel. If a client sends a hit message, the server should service that request fairly: it should not have to wait for another idle client to send a message before it receives a new card. (That is, use the select function.)
The second C program you will write is a client program that will interface with your server program via the protocol described above.
Your program should support being run in the following manner:
$ bjclient host [username]
host is the name or IP address of the server to connect to,
and is required.
username is the name to be used for the connection. If
username is not specified, the value of the environment variable
USER should be used. If the USER variable is not
set, use some resonable preset default string.
Your client program will connect to the server, introducing itself by sending a username, and reporting whether the connection is successful or denied. It will then report the number of decks in use on the server, and then allow the user to play.
For each round of play, your client program should prompt for the user to enter a bet amount, which is then sent to the server (according to the protocol explained above). If the cards have just been shuffled, it should be reported to the user. Within a round, each time the server sends the listing of the hands, the client will display the known hands to the user (in some reasonable format). Until the hand is complete, the client should accept a line from the user starting with an H or an S (uppercase or lowercase) to indicate the user's choice of hitting or standing.
If the user signals end of file instead of a bet, or bets zero, the client should terminate the connection to the server and print a message to the user indicating the final change in chips for the user.
The following might be a sample execution of the program.
$ ./bjclient localhost me Connected to 127.0.0.1 as me Playing with 6 decks. The cards have just been shuffled. Bet? 10 Dealer Richard me 7C 3H,4H 4C,JD (H)it or (S)tand? Dealer Richard me 7C 3H,4H,5C 4C,JD (H)it or (S)tand? hit Dealer Richard me 7C 3H,4H,5C 4C,JD,7D (H)it or (S)tand? STAND Dealer Richard me 7C 3H,4H,5C,JH 4C,JD,7D Dealer Richard me 7C,KC 3H,4H,5C,JH 4C,JD,7D Winnings: -5 10 You won! Your net winnings are now 10 chips. Bet? 0 Disconnecting... You won 10 chips.
#ifndef PORT #define PORT 30000 #endifand set in your Makefile something like:
PORT=10000 CFLAGS = -DPORT=$(PORT) -g -WallThe -D flag for the compiler tells gcc to define the symbol. The "#ifndef" tells the compiler to only include the code if the symbol hasn't already been defined.
You will commit to the a4
directory of your CSC209
repository the following files:
bjserver
and
bjclientMakefile
, containing commands to compile
your bjserver and bjclient
simply by running
make and allows us you specify the port as mentioned aboveYou are strongly encouraged to take advantage of the version control system and commit your work frequently so that you can keep track of your progress. Please note that perfectly fine (and even recommended) that you keep any additional files related to this assignment (such as files and scripts used for testing) under version control. The markers will simply ignore such files.