Encrypted Chat Room 4_Class Specifications(4)

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值