Code Monkey home page Code Monkey logo

ping-pong-client-server's Introduction

Overview

Simulate a ping pong game using server/client methodology. The Server program has a runServer() main server method that accepts connections and starts off a new thread by calling ServerThread class to handle each accepted connection. In client program, all clients connects to one server. The PingPong program is where the main class is and finally, a Ping Pong ball is represented simply using an empty serializable object.

Building the code

Compile all java programs in hw1 folder :
$ javac hw1/*.java

Specify the command line argument Usage: java PingPong <client|server> <serverHost> <port#>
We always start server first :
$ java hw1.PingPong server localhost 5005

Open another terminal, start client :
$ java hw1.PingPong client localhost 5005

Now the game starts infinitely. Then in the client-side terminal, kill the current game with a Ctrl+C command.

To start another game, stay in the client-side terminal, and start client again :
$ java hw1.PingPong client localhost 5005

Now the game starts infinitely. To stop all games, go to the server-side terminal, kill the server with a Ctrl+C command

Testing

  • Opened at least 3 terminals to simulate 1 server and at least 2 clients who are playing games simultaneously with the server. Then kill the games one by one, watch the change on the displayed game numbers in the output recognizing which game is killed and which games are still active.
  • Set delay time to make the output readable.
  • Tested the program using port 5005 and 5006 respectively.

Reflection

  • Wrote a PingPong for the main class with [server|client] option in command for Client and Server programs. This is a better design than repeating main class in both Client and Server program respectively.
  • Understand synchronization concept with example.
  • Understand why this is an "Multithreaded Server, Singlethreaded client" example.
  • Understand how the object/information is passed/exchanged between server and client

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.