'

Protocols of CardDatabase and CardWrite servers

CardDatabaseServer

Runs on mir54.ida.liu.se at port 7000.

The commands for the CardDatabaseServer are:

command: "getCardsNumber\n"
example: "getCardsNumber\n"
reply: number of cards, as string, with a new line character
example: "27\n"

command: "getCardInfo <number>\n"
example: "getCardInfo 3\n"
reply: name, file name, URL, thumbnail's URL, x, y, width, height separated by new lines
example: "Hut in the Forest\nhut_2.jpg\nhttp://www.ida.liu.se/~trapo/TDDB37/cards/hut_2.jpg\nhttp://www.ida.liu.se/~trapo/TDDB37/cards/thumbs/hut_2_t.jpg\n10\n350\n480\n190\n"

command: "exit\n" (might be used before close(socket), but is not really necessary)
If the commands are used incorrectly, you might get the following error messages as a reply:
"ERROR: empty request line\n"
"ERROR: bad card number <card>\n"
"ERROR: bad request string\n"
The command strings are case sensitive.  The cards are numbered starting with number 1. As this server is written in C++, each of its replies ends with the character '\0'.

CardWriteServer

Runs on mir53.ida.liu.se at port 9000.

Messages sent to CardWriteServer should be formatted in the following way:

the file name of the card should be sent first "<card file name>\n" followed by
"<file name of card with the message>\n" followed by
"<x> <y> <width> <height>\n" followed by
"<message line 1>\n" followed by 
"<message line 2>\n" followed by 
...
"<message line n>\n" ended with
"end-of-message\n".

example:
"hut_2.jpg\n"
"002-4189664-9234420.jpg\n"
"10 350 480 190\n"
"Hello World\n"
" \n"
" \n"
" \n"
"/a student\n"
"end-of-message\n".
Due to the limitations of this simple protocol, an empty line in the message should be encoded like " \n" (space, then new line).

As a reply you get back an URL of the new card, followed by new line, e.g. "http://www.ida.liu.se/~trapo/TDDB37/cards/temp/002-4189664-9234420.jpg\n"

If the message formatting is incorrect or some other error occurs, the reply string will be of the form "ERROR: <error message>\n".

Notes

Use the write function to send messages to the servers.
Example:
sprintf(buff, "getCardInfo %d\n", card);
write(socket, buff, strlen(buff) + 1);
Use the read function to read messages from the servers.
Example:
len = read(socket, buff, 256);
buff[len] = 0; /* just in case the server is not sending a proper string */
printf("%s", buff);
Use strtok in order to parse a message consisting of several tokens separated by newlines.