CS 580 Client-Server Programming

Spring Semester, 2009

Assignment

Assignment Index

© 2009, All Rights Reserved, SDSU & Roger Whitney

 San Diego State University -- This page last updated 2/3/09

SDwitter Description

You will be writing a small client-server system.  The system is modeled after Twitter. In Twitter people send small messages (up to 140 characters) which anyone can read. In our system, SDwitter, anyone can read the posted messages, but you have to be logged in to send messages. A user of SDwitter has a screen name and a password. A screen name has to be unique. When you read messages you can see the text of the message, who sent the message and when it was sent.

The protocol for the system is as follows. The client can send 6 commands to the server: "login", "messages", "newUser", "quit", "screenName", "transmitMessage". Connections to the server have state. The connection starts in the "start" state. In this state only commands "login", "messages", "newUser", "quit", and  "screenName" can be sent. After  a successful "login" command the connection is in the "authenticated" state. In this state only the commands "messages",  "quit", "screenName", and "transmitMessage" can be sent.

Commands

Two characters: ":" and ";" are used as meta characters in commands. The meta character ":" is used to separate keys and values in a command. The meta character ";" is used to end command parts (headers) and to end a message. A command always ends in two ";" characters, one to end the last part and one to end the command. Whitespace (spaces, tabs, line feeds and character returns) can be be used immediately before and after a meta character. So the following versions of the login command are both valid.

login;screenName:foo;password:bar;;

login;

screenName : foo;

password : bar;;

Values, which follow the meta character ":", may contain ":" or ":". In order that these characters are not confused as meta characters they must be escaped with a "\". Since the character "\" has special meaning it too must be escaped if it occurs in a value. If a user's password is "a:b;c\d" then it must be converted to "a\:b\;c\\d" before is it sent as part of the login command. The server removes the extra "\" characters.

Anytime there is an error on the server side the server return with an error message. The format is:

error:ErrorString;;

ErrorString is a description of the error. If it contains special characters it will be escaped.

login

Use to authenticate a user. The format of the command is:

login;screenName:aScreenName;password:aPassword;;

Where aScreenName and aPassword are strings that can contain any ascii character. They need to be escaped if they contain ":", "\" or ";".

The server response with one of the following:

ok:success;;

error:No such user;;

error:Invalid password;;

If the command is successful the connection moves into the "authenticated" state. Otherwise it remains in the "start" state.

quit

The format of the "quit" command is:

quit;;

The server responds with result below and closes the connection with the client.

ok:quit;;

screenName

This command is used to determine if a screen name is in use. The format of the command is:

screenName:aString;;

The server responds with one of the two responses below. If the screen name is not used be a user already the first response is returned. If a user has already selected that screen name the later response is sent.

ok:available;;

ok:used;;

newUser

This command is use to register a new user. If the command is successful the connection moves to the "authenticated" state. The format of the command is:

newUser;screenName:aScreenNameString;password:aPasswordString;;

aScreenNameString and aPasswordString are strings determined by a user. They need to be escaped if they contain ":", "\" or ";". The server responds with one of the following messages:

ok:success;;

error:ReasonForFailure;;

ReasonForFailure may contain ":", "\" or ";". If it does the characters will be escaped.

transmitMessage

This command is used to send a message to the server. It can only be sent when the connection is in the "authenticated" state. The format of the command is:

transmitMessage:messageString;;

messageString is the text the user wishes to send as a message. It needs to be escaped if it contains ":", "\" or ";". The server responds with one of the following messages:

ok:success;;

error:ReasonForFailure;;

ReasonForFailure may contain ":", "\" or ";". If it does the characters will be escaped.

messages

This command is used to get a list of messages from the server. The format of the command is one of:

messages;block:N;sender:aScreenName;;

messages;block:N;;

aScreenName is the screen name of a SDwitter user. It needs to be escaped if it contains ":", "\" or ";". If the first form of the command is used only the messages sent by that user are returned. Messages are returned in blocks of 20. If N is 1 then the most recent 20 messages are returned. If N is 2 then the next most recent 20 messages are returned. When N is large enough there will be no messages to return. If successful the server response is:

ok:K;

   text:aString1:sender:aScreenName1:time:aTimestamp1;

   text:aString2:sender:aScreenName2:time:aTimestamp2;

   text:aString3:sender:aScreenName3:time:aTimestamp3;

   ...

   text:aStringK:sender:aScreenNameK:time:aTimestampK;;

or

ok:0;;

K is the number of messages being returned. aStringM is the text of the M'th returned message. It will be escaped if needed. The most recent message is listed first. aScreenNameM is the screen name of the sender of the M'th message. It will be escaped if needed. aTimestampM is the time the M'th message was sent. The format for the time is:

mm/dd/yyyy hh:mm:ss

As the string contains ":" it is escaped. Time uses the 24 hour clock. Month (mm) is always two digits as is the day (dd). The year (yyyy) is given in 4 digits.

Sample Interaction

The interaction below assumes that the use with screen name foo has already registered and no one has sent any messages to the server yet.

Client Command

Server Response

login;screenName:foo;password:bar;;

ok:success;;

transmitMessage:Hello World;;

ok:success;;

transmitMessage:Hello \\2;;

ok:success;;

messages;block:1;;

ok:2;

text:Hello \\2:sender:foo:time:02/03/2009 13\:29\:45;

text:Hello World:sender:foo:time:02/03/2009 13\:29\:42;;

fuss;;

error:Invalid command f;;

quit;;

ok:quit;;