Class Specifications:
The attributes and operation specifications are written in UML notation.
Assume all attributes have private visibility.
If you need to access an attribute from another object, then use its get/set methods. If these methods have not been explicitly designed, you may implement them as needed.
As part of your implementation, you may add extra attributes if required.
However, DO NOT change the public interfaces of the operations. An exception to this is for the design of the GUI.
class Client
This class represents a single client which can request session keys from the server, and communicate with other clients.
attributes
name: String {unique name of the client consisting of one word}
server: Server {object reference to the Server object the client is “connected” to}
sessions: Collection(Session)
key: String {private key of client used for encryption of messages}
gui: ClientGUI
invariant
name is one word and unique
key must contain one or more capital letters that have an ASCII value between 65 and 90.
operation specifications
+ Client (name: String, key: String, server: Server)
-- parameterised constructor
pre: name is unique, server and key are valid
post: A ClientGUI object has been created and assigned to gui.
The server has been sent a reference to this object with a call to addClient(self).
A valid Client object is returned.
+ requestSession (name: String): Integer
-- sets up the communication session with selected user
pre: name corresponds to the currently selected user
post: A session request has been sent to the server by a call to
establishSession(self.name, name)
The session data (including the session key) has been obtained from the server.
A Session object has been created and initialised with the decrypted session data.
The session state has been set to WAIT_REPLY.
The session has been added to sessions.
The GUI display indicates that the session is in the WAIT_REPLY state.
The session.Id has been returned.
+ updateConnectedUsers (connectedUsers: String[])
-- updates the list of connected users on the GUI display
pre: connectedUsers contains the names of users connected to the server.
post: The list of connected users is displayed.
self is not included in the displayed list.
+ acceptSession (sessionData: SessionData, senderName: String)
-- accepts session data from the sender wanting to establish a communication session.
pre: sessionData is valid
post: a Session object has been created and initialised with the decrypted session
data.
The session has been added to sessions.
The session state has been set to ACCEPT_REJECT.
The GUI display indicates that the session is in the ACCEPT_REJECT state.
+ acceptCmd (cmd: String, sessionId: Integer)
-- accepts a command from the sender during establishment of communication session.
pre: cmd is valid2
post: for the session identified by sessionId
if state of the session is equal to WAIT_REPLY
if cmd = ACCEPT then
session state has been set to CHAT.
The GUI display indicates that the session is in the CHAT state.
else if cmd = REJECT then
session has been removed from sessions.
The GUI reflects the end of the session.
end if
else if state of the session is equal to CHAT
if cmd = END then
session has been removed from sessions.
The GUI reflects the end of the session.
end if
end if
+ sendCmd (cmd: String, sessionId: Integer)
-- sends a command to the receiver during establishment of communication session.
pre: cmd is valid
post: for the session identified by sessionId
server.sendCmd(cmd, sessionId, receiverName)3
if cmd = ACCEPT then
session state has been set to CHAT.
The GUI display indicates that the session is in the CHAT state.
else if cmd = REJECT then
session has been removed from sessions.
The GUI reflects the end of the session.
else if cmd = END then
session has been removed from sessions.
The GUI reflects the end of the session.
end if
+ acceptChatMessage (msg: String, sessionId: Integer)
-- accepts a chat message from the sender for the session identified by sessionId.
pre: msg is encrypted
post: The msg has been decrypted according to the session key associated with the sessionId.
Both the msg and the decrypted message are displayed on the GUI textdisplay.
+ sendChatMessage (msg: String, sessionId: Integer)
-- sends a chat message to the receiver for the session identified by sessionId.
pre: msg not null
post: msg has been encrypted according to the session key associated with the sessionId.
encrypted msg has been sent to the receiving client for this session
by calling server.sendChatMsg(msg, sessionId, receiverName)
msg and encrypted message are displayed on GUI textdisplay.