2. Goal and learning objectives
Instant messaging applications such as WhatsApp, WeChat, Facebook Messenger, etc. are widely
used with millions of subscribers participating in them globally. In this assignment, you will have
the opportunity to implement your own version of an instant messaging application. In addition to
basic messaging functionality, you will also implement many additional services that are available
in many of the aforementioned applications. Your application is based on a client server model
consisting of one server and multiple messaging clients. The clients communicate with the server
using TPC. The server is mainly used to authenticate the clients and direct the messages (online or
offline) between clients. Besides, the server also has to support certain additional functions
(presence notification, blacklisting, timeout, etc.). The extended version asks you to implement
peer-to-peer messaging that bypasses the server.
2.1 Learning Objectives
On completing this assignment, you will gain sufficient expertise in the following skills:
1. Detailed understanding of how instant messaging services work.
2. Expertise in socket programming.
3. Insights into designing an application layer protocol.
3. Assignment Specification
There are two versions of this assignment, a standard version (with a total of 13 marks) and an
extended version (with a total of 15 marks of which 2 marks are bonus marks). The
specifications for the extended version can be found in Section 5 of the specification. Note that the
bonus marks may not be proportional to the amount of extra work that you will have to do. They are
there to encourage you to go beyond the standard assignment. The bonus marks can be used to
make up for lost marks in the lab exercises and the second programming assignment but NOT for
any of the exams (mid-session and final).
Updates to the assignment, including any corrections and clarifications, will be posted on the
subject website. Please make sure that you check the subject website regularly for updates.
2
The assignment includes 2 major modules, the server program and the client program. The server
program will be run first followed by multiple instances of the client program (Each instance
supports one client). They will be run from the terminals on the same and/or different hosts.
For the standard version, all messages between clients MUST be sent via the server. The extended
version asks you implement additional functionality whereby two users can exchange messages
with each other directly (i.e. bypassing the server) in a peer-to-peer fashion.
4.1. Server
The server has the following responsibilities –
User Authentication – When a new client requests for a connection, the server should prompt the
user to input the username and password and authenticate the user. The valid username and
password combinations will be stored in a file called credentials.txt which will be in the same
directory as the server program. An example credential.txt file is provided on the assignment page.
Username and passwords are case-sensitive. We may use a different file for testing so DO NOT
hardcode this information in your program. You may assume that each user name and password
will be on a separate line and that there will be one white space between the two. If the credentials
are correct, the client is considered to be logged in (i.e. online) and a welcome message is
displayed. When all messaging is done, a user should be able to logout from the server.
On entering invalid credentials, the user is prompted to retry. After 3 consecutive failed attempts,
the user is blocked for a duration of block_duration seconds (block_duration is a command line
argument supplied to the server), and cannot login during this duration (even from another IP
address). While a user is online, if someone uses the same username/password to log in (even from
another IP address), then this new login attempt is denied. If the username is invalid then block
access from that IP address for block_duration.
Timeout – The server should keep track of all online users. If the server does not receive any
commands from a user for a period of timeout seconds (timeout is a command line argument
supplied to the server), then the server should automatically log this user out. Note that, to be
considered active, a user must actively issue a command. The receipt of a message does not count.
Presence Broadcasts – The server should notify the presence/absence of other users logged into the
server, i.e. send a broadcast notification to all online users when a user logs in and logs out.
List of online users – The server should provide a list of users that are currently online in response
to such a query from a user.
Online history – The sever should provide a list of users that logged in for a user specified time in
the past (e.g. users who logged in within the past 15 minutes).
Message Forwarding – The server should forward each instant message to the correct recipient
assuming they are online.
Offline Messaging – When the recipient of a message is not logged in (i.e. is offline), the message
will be saved by the server. When the recipient logs in next, the server will send all the unread
messages stored for that user (timestamps are not required).
Message Broadcast – The server should allow a user to broadcast a message to all online users.
Offline messaging is not required for broadcast messages.
3
Blacklisting – The server should allow a user to block / unblock any other user. For example, if user
A has blocked user B, B can no longer send messages to A i.e. the server should intercept such
messages and inform B that the message cannot be forwarded. Blocked users also do not get
presence notifications i.e. B will not be informed each time A logs in or logs out.
4.2. Client
The client has the following responsibilities –
Authentication – The client should provide a login prompt to enable the user to authenticate with
the server.
Message – The client should allow the user to send a message to any other user and display
messages sent by other users. The client should also allow the user to send a broadcast message to
all online users.
Notifications – The client should display presence notifications sent by the server about users
logging in and out from the server.
Find users online – The client should provide a way for the user to obtain a list of all the users
currently online from the server.
Find online history – The client should provide a way for the user to obtain a list of all users who
had logged in within a user specified time period.
Blacklist – The client should allow a user to block a user from sending any further messages. The
client should also allow a user to unblock a user that was earlier blocked.
4.3 Commands supported by the client
After a user is logged in, the client should support all the commands shown in the table below. For
the following, assume that commands were run by user A.
Command Description
message Send to through the server. If the user is
online then deliver the message immediately, else store the
message for offline delivery. If has blocked A, then a
message to that effect should be displayed for A. If the is
not present in the credentials file (i.e. invalid user) or is self (A)
then an appropriate error message should be displayed. The used in our tests will be a few words at most.
broadcast Send to all online users except A and those users who
have blocked A. Inform A that message could not be sent to some
recipients.
whoelse This should display the names of all users that are currently
online excluding A. Users can be displayed in any order.
whoelsesince