Due date: Tuesday, Mar 13th, 2012
In this project you will develop a matchmaking service for games. The service will be the 'server' and clients will be able to use a simple text protocol so that they can see who else is available to play a game.
This project will consist of two pieces: the client and the server. You will begin by creating the server because we'll be able to interact with it through telnet before we automate it via the client.
When you start your server, it must read three arguments from the command line:
The server will bind and listen to the port. When a client connects, a new thread will be spawned to handle the socket. You should use pthreads for threading in Linux.
The server will listen to the following commands:
JOIN username LEAVE LIST PONG
As a server, it will send only one command:
PING
All commands are case-insensitive. When a client wants to join the service, it first connects to the server, and then sends a JOIN command with the username of the player to join. Note, this is all sent as plain ASCII text, thus you will not need any conversions to or from integer representations. Usernames will also only consist of alphanumeric characters and have no spaces or other funny characters.
After a client joins, the server initiates a PING command to the client. The client responds with a PONG. The server records when the PING was sent, and calculates how long it takes to receive the PONG. This value is stored and returned later when the client uses the LIST command. The server may send a PING at any time and the client should respond whenever it gets it.
When a client wants to leave the matchmaking service, they send a LEAVE command. If the client does not send anything for at least TIMEOUT seconds, they are disconnected. Note that TIMEOUT is configured on the command line when starting the server.
If a client wants to know who is currently looking to play a game, they use the LIST command. The server returns a list of all players and their RTTs to the server. Each player and RTT are on individual lines (the lines are separated by newline characters).
To create the client part of the project, we will have a program that takes 3 arguments:
The client, when it starts up, will connect to the server and JOIN immediately. Thereafter it will send a LIST command to the server every INTERVAL seconds so that it's not disconnected. It will also need to automatically respond to PING commands. It should echo everything that it receives on its socket from the server to the screen.
Before you start, you should familiarize yourself with the telnet command. You've seen me use this in class to talk to a web server. You will use this to test your server long before you ever write your client. You can simply telnet to the server IP and port and type in the text commands and your server should parse them in the same way that it will with the client you'll be writing after you write the server.
SERVER PLAYERJOIN username RTT PLAYERLEAVE username
The SERVER distinguishes the connection from being a server and not a client. Clients may connect to either server. When a player joins one server, the server sends the PLAYERJOIN command to the other server with that player's username and the result of the PING/PONG RTT test in milliseconds. The username and RTT are separated by whitespace. When a player leaves, the server sends a PLAYERLEAVE with the username to the other server.
Note that the point of this is to synchronize their list of players so that now when a client runs LIST, they get an updated list consisting of players from both servers.
You will submit your source under your repository with a new directory for your project called p3. You must include a makefile or an Eclipse project to compile your source into an executable called 'match'. The naming is important because we try to automate as much as possible!