I have already touched this subject a few times. Here is a more thorough explanation.
What it does
Chess communication protocols are used to help chess engines communicate with an interface.
The protocol sends information about the game on a certain form, and receives moves and information from the engines based on given standards.
The main advantage is of course that you only need one interface to run several different engines. As long as they support the protocol used you will be able to run them.
The two main protocols
There are two main chess communication protocols. WinBoard and UCI.
WinBoard (or xboard, they are the same) was developed by Tim Mann and is probably the most common protocol, in recent years however the UCI protcol developed by Rudolf Huber and Stefan Meyer-Kahlen (creator of the Shredder engine), has gained ground.
The specifications can be found here:
UCI specifications
WinBoard specifications
How they work
The main principle is the same for both protocols. The interface (be it winboard or uci compatible) sends strings with information, and handles responses from the engine.
To be able to catch the information sent from the interface you need a loop that looks for input. In Java it could look like this:
BufferedReader reader =
new BufferedReader(new InputStreamReader(System.in));
for(;;) // Endless loop
{
String command = reader.readLine();
if(command.equals("something"))
{
doSomething();
}
}
"usermove e2e4"
When the engine receives this input it should make it on the board and start thinking, and then send a response like this:System.out.println("move e2e4");
This tells the interface that the engine want to make the move."position startpos moves e2e4 e7e5 g1f3"
or"position fen [a fen string] moves e7e5 g1f3"
The 'startpos' indicates the game started from the initial position, and the moves following 'moves' are the moves played since the startposition. If it is a fen-string instead it indicates that the game probably started from some other position.System.out.println("bestmove e2e4");
There is a 'go' command in WinBoard as well, but this is only sent to make the engine leave 'force' mode after setting up the board, or if we want the engine to play white from the initial position.