Operating Systems Spring 2011

Exercise 5: A Local & Temporal Twitter

Yes, indeed, you're gonna have to serve somebody...
                                                                    Bob Dylan, Gotta Serve Somebody

Due Date: 30/5/2011

Before you start, don't forget to read the course guidelines!

Assignment

You are going to build a basic twitter-like service - with users "following" other users and users messaging each other. This will necessitate a server (which needs to be online for the operation to work) and various clients (i.e., the users) which converse via the server.

Part 1: The Server

Implement a program, called twitServer, that accepts a single variable - its port number. This server will listen to incoming connections on the specific port, and handle client requests. The server should also maintain a log file (the file should be named twitServer.log), which includes all the commands it received (see command table below for instructions on log format). At any time the user can enter EXIT in the stdin (terminal) of the server and the server will disconnect all the clients and exit.

While we are implementing a twitter like service, the service is temporary - there is no need for the server to remember which client follows which between different sessions, nor does it need to remember a client after it disconnected (i.e., if a client A followed client B, if client B disconnects and then connects again, client A no longer follows client B).

Part 2: The Client

Implement a program, called twitClient, which takes 3 program arguments - client name, server address, and port, hence usage is:
twitClient <CLIENT NAME> <SERVER ADDRESS> <SERVER PORT>

Upon execution the client will try to connect to the specified server and pass its name to the server (you decide the protocol for this). After successfully connecting the client will print "Connected successfully" to its terminal screen and wait for commands from stdin (keyboard). If a client tries to connect and the given <CLIENT NAME> is already in use, the client should fail to connect to the server - an appropriate error message should be printed to the screen, and the program should exit(1).

The client will support all the commands specified below. A command is defined to be one line, i.e. all the text typed until ENTER is pressed is considered a single command. Every command entered is sent to the server. In addition, the client will also recognize the command EXIT, which will cause the client to disconnect from the server and exit. In case the server exits first the client should behave reasonably (=not crash), but you can choose the way (detail it in the README file).

When the client receives a message (including errors) from the server it will print it immediately on the screen. Errors should be preceded by Error:.

Part 3: Commands from clients to the server

Function Command Arguments Command description Log format
Connect When client connects to server<CLIENT NAME>\t connected.\n
Disconnect EXITWhen client disconnects from server<CLIENT NAME>\t disconnected.\n
Follow FOLLOW<SOME CLIENT NAME>Any messages from <SOME CLIENT NAME> will be sent to the requesting client. A client may use this command even if he already follows <SOME CLIENT NAME> - there will be no effect. If <SOME CLIENT NAME> doesn't exist, the message Error: <SOME CLIENT NAME> does not exist should be sent to the requesting client.<CLIENT NAME>\t followed <SOME CLIENT NAME>.\n
Unfollow UNFOLLOW<SOME CLIENT NAME>No further messages from <SOME CLIENT NAME> will be sent to the requesting client. A client may use this command even if he doesn't follow <SOME CLIENT NAME> - there will be no effect. If <SOME CLIENT NAME> doesn't exist, the message Error: <SOME CLIENT NAME> does not exist should be sent to the requesting client.<CLIENT NAME>\t unfollowed <SOME CLIENT NAME>.\n
Twit TWIT<MESSAGE>The message must be no more than 140 characters, and it needs to be sent to all clients which are following the twitting client (in the case of extremely unpopular clients, no message will be sent). The format that needs to be sent to the following clients is:
<HOUR>:<MINUTES>::<CLIENT NAME> - <MESSAGE>
With the hour & minute being the time the message is broadcast.
<CLIENT NAME>\t twitted <MESSAGE>.\n
Direct message DM<SOME CLIENT NAME>@<MESSAGE>The message must be no more than 140 characters, and it should be sent only to <SOME CLIENT NAME> whether he follows <CLIENT NAME> or not. The format that needs to be sent to the intended client is:
<HOUR>:<MINUTES>::<CLIENT NAME> - @<SOME CLIENT NAME>--<MESSAGE>
With the hour & minute being the time the message is broadcast. If <SOME CLIENT NAME> doesn't exist, the message Error: <SOME CLIENT NAME> does not exist should be sent to the requesting client.
<CLIENT NAME>\t direct messaged <SOME CLIENT NAME>\t <MESSAGE>.\n
Who WHOReturns the list of clients currently connected to the sever (alphabetically), e.g: <CLIENT NAME> \t <CLIENT NAME>\t ...<CLIENT NAME>\t Who.\n

The log should be written even in cases were there was some sort of error (e.g., <SOME CLIENT NAME> was not found).

Background reading and Resources

A good tutorial: Network Programming.
The Sockets API system calls:
socket(2), bind(2), listen(2), accept(2), connect(2), send(2), recv(2), close(2).
Auxiliary functions:
select(2),gethostbyname(3).

Submission

Submit a tar file on-line (named ex5.tar) containing the following: The README file should include the following:
  1. Your logins and IDs.
  2. Explain your design, and specifically the protocol used between the clients and the server. Explain what were your considerations in choosing this design, and how you would extend it easily to support more commands.
  3. Any additional information useful for the grader.

Guidelines

Note that the protocol between the clients and the server is up to you. In other words, you decide exactly what format to use when passing information from one to the other. In particular, you should decide what to do if some command fails. Basic guidelines are as follows: Don't forget to check the return value of all system calls!!!