class Server
This class represents a server that manages the encryption keys, and maintains a list of currently connected clients. It is also responsible for handling message transmission between the clients.
attributes
clientSet: ClientSet
operation specifications
+ Server ( )
-- constructor
pre: none
post: A ClientSet object has been created and assigned to clientSet.
+ addClient (client: Client)
-- adds a new client to the clientSet.
pre: client not null
post: client is added to the clientSet.
For all clients in clientSet, the updateConnectedUsers message has been sent.
+ disconnectClient (id: Integer)
-- deletes the client with matching id from the clientSet and sends a message to each client informing them of the update to the list of connected users.
pre: none
post: The client object with matching id is deleted from the clientSet.
For all clients in the clientSet, the updateConnectedUsers message has been sent.
+ establishSession (nameC1: String, nameC2: String): SessionData
-- After generating a random session key for C1 and C2 to communicate to each other, it encrypts two copies of it: one in C1’s key and the other in C2’s key. Then, it sends the session data for C2 to C2. It returns the session data for C1.
pre: nameC1 and nameC2 are valid
post: The random session key has been generated and encrypted for both clients.
sessionData for C2 has been created and sent to C2 by sending the message
acceptSessionData(sessionData)
sessionData for C1 has been returned.
+ sendCmd (cmd: String, sessionId: Integer, nameC2: String)
-- transmits a command message from C1 to C2.
pre: cmd valid
post: The command message received from C1 has been sent to C2 by sending the
message acceptCmd(cmd, sessionId)
+ sendChatMsg (text: String, sessionId: Integer, nameC2: String)
-- transmits a chat message from C1 to C2.
pre:
post: The chat message received from C1 has been sent to C2 by
sending the message acceptChatMessage(text, sessionId)
- generateRandomKey (): String
-- Generates a random session key.
pre: none
post: A valid session key is returned, which contains one or more capital letters that
have an ASCII value between 65 and 90.
Encrypted Chat Room 4_Class Specifications(4)
最新推荐文章于 2005-04-22 14:30:00 发布