Skip to content

Build and Run

BrandonRobare edited this page Jun 2, 2026 · 1 revision

Build and Run

Dependencies

netPong needs a C compiler and the ncurses development headers. The terminal drawing uses curses (#include <curses.h>), and the Makefile links against ncurses with -lncurses.

On Debian or Ubuntu:

sudo apt-get update
sudo apt-get install -y libncurses-dev

The networking uses only the standard BSD socket API and POSIX headers, so no extra library is needed for that side.

Build

make

The Makefile compiles pong.c, paddle.c, net.c, and protocol.c into objects and links them into one binary named pong. It builds with -Wall -Wextra -pedantic and compiles clean with no warnings. To remove the binary and the objects:

make clean

The continuous integration workflow in .github/workflows/ci.yml runs the same build on Ubuntu after installing libncurses-dev, and the badge in the README reflects that build.

Run

netPong is one program that starts in two roles depending on its arguments.

Start the server with a port number:

./pong 2001

It prints waiting for connection on port 2001... to stderr, then waits for a client. Nothing draws on screen until a client connects.

Start the client with the server's host name and the same port:

./pong localhost 2001

Use the server's host name or IP in place of localhost to play across two machines. Both windows come up as soon as the TCP connection is established. The client serves the first ball.

If you run the program with the wrong number of arguments, it prints the usage:

usage: ./pong <port>               (server)
       ./pong <hostname> <port>    (client)

Controls

  • k: move your paddle up
  • j: move your paddle down
  • Q: quit and notify the opponent

Your keys work while the ball is on your court. While you wait for the ball to come back, the local keyboard is idle, so a Q press during the wait does not register until the ball returns. That tradeoff is explained on the Roadmap page.

Endgame

A game lasts for a fixed number of balls, announced in the SERV message and tracked as balls_left on both sides. After the last ball, the two processes exchange DONE and QUIT, both windows close, and each prints its final score:

Final score: Me: 2  <opponent>: 1

Pressing Q mid-game sends QUIT to the opponent, and both windows exit.

Clone this wiki locally