Assignment1 Handout COMP3234 ELEC3443
Assignment1 Handout COMP3234 ELEC3443
B. Client Basics
The client program takes 2 parameters: (1) hostname or IP address of the server; (2) listening port of
the server.
Upon start, the client connects to the server at the IP and port by setting up a TCP connection. After
the connection is successfully established, the client program goes to the stage of “user authentication”
described as follows.
1. User Authentication
The client prompts its user the following on its terminal:
Please input your user name:
and then waits for the user to input the user name. After the user has input the user name, the client
prompts:
Please input your password:
and then waits for the input of the password. After the user has input its password, the client sends
the user name and password to the server, with a message in the following format:
/login user_name password
(Note: user_name and password should be replaced by the actual user name and password.)
If the authentication at the server is successful, the server thread (which handles the user’s connection)
sends the following message back to the client, and goes to the stage of “in the game hall” described
next.
1001 Authentication successful
Otherwise, the server responds with the following message and the authentication procedure is
repeated (i.e., the client should prompt the user to enter name and password again):
1002 Authentication failed
If the room has already been occupied by two players, the entering player will receive the following
message from the server and stay in the game hall:
3013 The room is full
3. Playing a Game
Upon receiving a message 3012 from the server, the client waits for the user to enter a boolean value,
i.e., true or false, and then sends the input to the server via the following message:
/guess true_or_false
(Note: true_or_false should be replaced by the entered true (or false).)
Upon receiving /guess messages from both of the players, if their guesses are the same, the result is
a tie, and the server sends the following message to both players:
3023 The result is a tie
Otherwise, the server generates a random Boolean value, r. The player whose guess is r becomes
the winner, and the other loses the game. The server sends the following the message to the
winner:
3021 You are the winner
The server sends the following message to the loser:
3022 You lost this game
After receiving any of the above messages, the game ends and the states of both players return to “in
the game hall”.
Upon receiving a /exit command from the client, the server responds with
4001 Bye bye
Upon receiving the response from the server, the client program closes its socket and then quits.
Whenever a player exits from the system, the server thread (that handles the user’s connection)
closes the corresponding socket and then ends.
5. Dealing with incorrect message format
If the server receives a command message in the wrong format, it simply responds with
4002 Unrecognized message
For better understanding of the interactions between clients and the server, please refer to example
interactions given in the Appendix.
V. GROUP OR INDIVIDUAL
You should work on this assignment individually, or in a group with at most two students.
You will get 10% bonus mark if you work on the assignment individually, i.e., your mark will be your
original mark * 1.1, upper bounded by the full mark of 100.
VI. SUBMISSION
You should submit the following files in a zip file, named as a1-yourstudentid.zip (individual work) or
a1-studentid1-studentid2.zip (group work; only one submission by one of the group members is
needed for each group):
(1) GameServer.py
(2) GameClient.py
(3) A readme file to provide any additional information on the implementation and execution of your
programs that you deem necessary for us to know.