View on GitHub

Ball Drop Game

A game to demonstrate TCP sockets

Download this project as a .zip file Download this project as a tar.gz file

This is a multiplayer game in which players collaborate to keep a ball from hitting the ground. Each player has a paddle, and can bound the ball off her paddle. When the ball bounces off your paddle, you get a point. Only the first bounce counts, though; subsequent bounces don't get you points. But if the ball bounces off another player's paddle then back to yours, you score again. You can keep scoring forever by bouncing the ball back and forth.

Here's a video of the game in action:

The game is a networked application. Players log in by making a TCP socket connection to the IP address of the computer on which the game is running. For example, if the game is running on a computer with the IP address, then you'd make a connection to port 8080, and you'd be connected.

The simplest connection you can make to the game is via a command line interface, using telnet, like so:

$ telnet 8080

The game itself, BallDropServer, is written in the Processing programming environment, so you'll need to download the Processing IDE in order to run it.


The game clients can be written in any programming environment, and for any hardware you wish, as long as your environment can connect to a network and make a TCP socket connection. I've written clients for a few platforms below:

Communication Protocol

When a client connects to the server, the server will send back a greeting and the instructions for controlling a paddle, as follows:

l = left, r = right, u = up, d = down
x = exit
1 point for each time the ball hits a new paddle
(minimum 2 players)

The client can then send the following commands:

Game Play

The game starts when the first new player logs in. Balls will drop from the top of the screen, and remain in play until they reach the bottom of the screen. To score the most points, bounce the ball off as many paddles as you can.

The goal is to get the highest collective score.

The game ends when five balls have dropped. When the game is over, the group's scores will be displayed.

The game in its current version does not send the player any information about the ball or the state of the other players. In order to play the game, you have to be physically present to view the screen of the computer on which the game is running.

Getting Started with New Boards/New Libraries

All of the microcontroller examples for this game as of Feb 2016 can be programmed using the Arduino IDE. If you're using a third-party board like the ESP8266 modules, you'll need to install the board using the Boards Manager in the IDE. You'll probably also need to install a library using the Library Manager as well. This section explains how to do that, for IDE version 1.6.7

or later. To start with, download the Arduino IDE, version 1.6.7 or later.

The Boards Manager

To install new board definitions, for example the ESP8266, click on the Tools menu, and choose Board... --> Boards Manager. Use the search bar to search for your board. If it's there, install it, then close the Boards Manager, and you should see your board show up in the Boards menu when you click on it next.

If your board is not listed in the boards manager, you'll need to add the repository for it to the Preferences. Click on the Arduino menu, choose Preferences, and look for the field caled Additional Boards Manager URLs. Click the button to the right of it and add your board's repository URL to the list. Here are a couple of URLs you might want:

Once you've added your URL, click OK to exit the Preferences menu and restart the IDE. Your board should show up in the Boards menu now.

The Library Manager

The Arduino WiFi101 shield and the MKR1000 both use the same WiFi module, so you can use the same library, WiFI101, to program both of them. The ESP8266 has its own WiFi library, but the API is similar. You can find installed libraries under the Sketch menu, Include Libraries option. YOu can find examples for them in the File Menu, Examples option.

To install new libraries, for example the WiFi101 library or the ESP8266 libraries, click on the Sketch menu, and choose Include Library... --> Manage Libraries. Use the search bar to search for your library. If it's there, install it, then close the Library Manager, and you should see your Library show up in the Sketch --> Include Library menu and the File --> Examples menu when you click on either of them next.

If your library is not listed in the library manager, you can add it as a folder or .zip file using the Sketch --> Include library option as well. Just click Add .ZIP Library and follow the directions from there.

Once you've got your board installed and the libraries it needs, you're ready to use the examples in this repository.