Using cs101.comm.Announcer

Announcer is a class that allows your server to announce itself to any clients over the local network. This means that your client doesn't need to already know or prompt the user for the server host name and port. Instead, the client transmits a special packet looking to match a server name. If a message comes back, it contains the server and port information the client needs to connect.

Downloading the library

To get started, you need to download the announcer library and add it to your project.

There are two classes you need to know about:

GameInfo
Information about the game, including the name of the server and the port number on which the server is listening. Your server code should create a GameInfo as soon as it has set up a ServerSocket.
Announce
Constructor causes it to start announcing the game. Also contains static methods for finding a particular game if it exists.

Examples

You can use the sample client and server communicator that uses the Announcer class to help you write your own versions:

In a nutshell, the Server starts a ServerSocket, creates a GameInfo object, given the ServerSocket's local port number, and creates a new Announcer to announce the game. The client simply calls one of the static find methods to get a GameInfo object about the game. It can then use the host and port information embedded within the GameiInfo object to connect to the server.