Online Rock Paper Scissors Game between a client and a server
DOCUMENTATION: ONLINE ROCK-PAPER-SCISSORS GAME
Usage Instructions: By default, the server will run on local host. Therefore, the default address for client is “localhost:port/play”. Open two command prompts, type following commands:
- javac MyServer.java java MyServer
References:
- CMU course 08-722 class notes
- https://www.journaldev.com/7148/java-httpurlconnection-example-java-http-request-get-post
- http://www.rgagnon.com/javadetails/java-have-a-simple-http-server.html
- https://docs.oracle.com/javase/8/docs/jre/api/net/httpserver/spec/com/sun/net/httpserver/HttpServer.html
- https://buddhimawijeweera.wordpress.com/2014/12/25/creating-http-server-with-java/
To-Do (for running on Eclipse IDE):
- To use Sun’s packages for HTTP, you need to disable error prompts in Eclipse: Project properties -> Java Compiler -> Errors/Warnings -> Deprecated and restricted API https://stackoverflow.com/questions/9579970/can-not-use-the-com-sun-net-httpserver-httpserver
Time Taken:
- ~7 hours
Design Decisions / Features:
- Server-intensive model – All the error handling and computation is taking place at the server. This makes the client-side processing and light
- Use of Enum – Rock, Paper, Scissor are enums and not just strings
- All the code follows the coding convention
- Use of Java 8
- Rock, Paper, Scissor input string is ignorant of case to handle variation in input.
- Client can send both HTTP GET and POST requests
- Server supports both HTTP GET and POST requests
- Best-of-n (please note – the client must reconnect for each round)
- My own extension – A secure online Rock-Paper-Scissor game
- Use of SHA-256 encryption to send secure messages over the internet
Limitations / Possible improvements:
- Used many string concatenations. Can use String Builder class in Java instead.
- All methods need not be static. Can instantiate the object before calling methods.