This is a project created for the BYU CS 240 (Advanced Programming Concepts) course.
This project demonstrates mastery of proper software design, client/server architecture, networking using HTTP and WebSocket, database persistence, unit testing, serialization, concurrency, and security.
The chess server is deployed to an AWS EC2 instance.
A simple frontend can be accessed here and contains an interface for making all the
http API calls as documented below. To play a game through the command-line client, download and run the included
client.jar file.
The application implements a multiplayer chess server and a command line chess client.
| Endpoint | HTTP Method | Path | Header | Body | Returns |
|---|---|---|---|---|---|
| Register | POST | /user | {username, password, email} | authToken | |
| Login | POST | /session | {username, password} | authToken | |
| Logout | DELETE | /session | authToken | {} | |
| List Games | GET | /game | authToken | {gameID, whiteUsername, blackUsername, gameName}[] | |
| Create Game | POST | /game | authToken | {gameName} | gameID |
| Join Game | PUT | /game | authToken | {ClientColor, gameID} | {} |
| Clear Application | DELETE | /db | {} |
- Install all dependencies as specified in the
pom.xmlfiles. - Run the server using the
client/src/main/java/Mainclass. - Run multiple concurrent clients using the
server/src/main/java/server/Mainclass.
Open the project directory in IntelliJ in order to develop, run, and debug the code using an IDE.
You can use the following commands to build, test, package, and run the code.
| Command | Description |
|---|---|
mvn compile |
Builds the code |
mvn package |
Run the tests and build an Uber jar file |
mvn package -DskipTests |
Build an Uber jar file |
mvn install |
Installs the packages into the local repository |
mvn test |
Run all the tests |
mvn -pl shared test |
Run all the shared tests |
mvn -pl client exec:java |
Build and run the client Main |
mvn -pl server exec:java |
Build and run the server Main |
These commands are configured by the pom.xml (Project Object Model) files.
There is a POM file in the root of the project, and one in each of the modules.
The root POM defines any global dependencies and references the module POM files.
- First ensure you have a running AWS EC2 instance with Java installed and security group allowing inbound traffic on ports 22 and 8080.
- Also install and run mysql and set up a database for the chess server.
- Create a
db.propertiesfile inserver/src/main/resourceswith the following content:db.host=localhost db.port=<your-database-port> db.name=<your-database-name> db.user=<your-database-username> db.password=<your-database-password> - Create the corresponding database and user
- Create a
- Build the client jar with dependencies:
mvn package -pl client -DskipTests - Copy it to server's resources web directory so that it can be downloaded from the server
cp client/target/client-jar-with-dependencies.jar server/src/main/resources/web/client.jar - Build the server jar:
mvn package -pl server -DskipTests - Deploy the server jar to the EC2 instance:
scp -i <path-to-pem> server/target/server-jar-with-dependencies.jar user@server:/path/to/deploy/server.jar - SSH into the instance:
ssh -i <path-to-pem> user@server - Run the chess server:
java -jar /path/to/deploy/server.jar - Verify the server is running by navigating to
http://<server-ip>:8080in a web browser.
- Create a systemd service file
/etc/systemd/system/chess.servicewith the following content:Description=Chess Server After=network.target mysql.service Requires=mysql.service [Service] Type=simple ExecStart=java -jar /path/to/deploy/server.jar 8080 [Install] WantedBy=multi-user.target - Enable and start the service:
sudo systemctl enable chesssudo systemctl start chess - Check the status of the service:
sudo systemctl status chess - Reboot instance and confirm the service starts on boot:
sudo reboot
