QQ chat Analysis notes

Source: Internet
Author: User
Tags sendmsg
The chat room program we will create is structured according to the client/server model. The customer will randomly connect to the chat room. If a chat room receives a customer, the customer will send a message to the chat room. Then each message is broadcast in the chat room. In addition to the sender, each customer who establishes a connection with the chat room will receive a copy. note: The number of people in the chat room is online. When the number of people reaches online, users cannot connect.

Requirement Analysis:
Participants: selanger, Administrator
Use case diagram
Color wolf ---------------- log on to the chat room
| --------------------- Send greetings to mm
-------------------- System forwarding MM's dislike of the color wolf.
| ---------------------- Exit the chat room

Administrator ---------------- adds a chat room
| ----------------------- Delete a chat room
| ---------------------- Modify chat room information

Use Case Specification
Use Case 1: log on to the chat room
1. The client obtains the address of the chat room.
2. The system places the address of a chat room.
3. The customer connects to the chat room
4. The system returns the successful logon information.
5. End of use case
Prerequisites: you must first know the address of the chatting room server.
Post condition: Add a user to a chat room
Backup event stream 1
4. When the number of connected chat rooms reaches the upper limit, the system returns a message indicating that the chat room is full.
Alternate event stream 2
4. When a user has logged on to a chat room and the user has logged on to the chat room again, the system returns the login message and

Use Case 2 color wolf sends greetings to mm
1. The client sends messages to the chat room
2. The system returns confirmation information.
Prerequisites: you must first log on to and change the chat room.
Post condition: a message to be sent to the chat room is added.

Case 3 system forwarding MM's contempt for the color Wolf
1. The system sends a message of another customer to the client.
2. The client submits an application for confirmation to the chat room.
Prerequisites: you must first log on to the chat room.
Post condition: the chat room does not send this message to selanger.

Case 4 Add a chat room as an administrator
1. Enter the name and number of new chat rooms
2. The system returns a successful message.
Prerequisites: the Administrator must first log on to the system.
Post condition: the system adds a chat room

Case 5: The Administrator deletes a chat room
1. Enter the number of the chat room to be deleted.
2. The system returns a successful message.
Prerequisites: the Administrator must first log on to the system.
Post condition: reduce a chat room in the system
Remarks event stream 1
2. When there are users in the chat room ??????? (How can I solve this problem ?)

Use Case 6: log out of the chat room
1. Submit an exit request to the chat room
2. The system returns confirmation information.
Prerequisites: Used to log on to the chat room.
Post condition: the chat room will reduce one user

Case 7 modify chat room information
1. Enter the modified chat room information, including the name of the chat room and the number of people going online.
2. The system returns a successful message.
Prerequisites: The administrator must log on to the system.
Post condition: the chat room information is modified ???)

Rough Class Analysis:
Tcharroomserver tcharroom tclient
Count maxcount clientname
Charroom []: tcharroom clientcount charroomname
Address clients []: tclient recvmsgs: tmessage
Msgcount recvmsgcount
Msgs []: tmessage sendmsg (MSG: string)
Tmessage
Clientname;
MSG

Rough Class Analysis:
Tcharroomserver tcharroom tclient
Count maxcount clientname
Charroom []: tcharroom clientcount charroomname
Address clients []: tclient recvmsgs: tmessage
Msgcount recvmsgcount
Msgs []: tmessage sendmsg (MSG: string)
Tmessage
Clientname;
MSG

Implementation
1 ttestchar = Class (ttestcase)
Private
SRV: tcharroomserver;
Charroom: tcharroom;
Cliarr: array [0 .. maxclient] of tclient;
Protected
Procedure setup (); override;
Procedure teardown (); override;
Published
Procedure testoneclient ();
Procedure testmaxconnect ();
End;
.//...
Procedure ttestchar. Setup ();
VaR
I: integer;
Begin
SRV: = tserver. Create;
Charroom: = tcharroom. Create (SRV );
Charroom. charname: = 'yihongyuan ';
For I: = 0 to MaxClient-1 do
Cliarr [I]: = tclient. Create;
End;

Procedure ttestchar. teardown ();
VaR
I: integer;
Begin
For I: = 0 to MaxClient-1 do
If assigned (cliarr [I]) then
Freeandnil (cliarr [I]);
SRV. Free;
End;

Procedure ttestchar. testoncclient ()
Begin
Check (SRV. charroom [0]. charname = 'yihongyuan ');
Check (cliarr [0]. Connect ('srv') = true );
Check (cliarr [0]. charroomname = 'yihongyuan ');
Check (SRV. charroom [0]. Client [0]. clientname = 'wollong ');
End;

Procedure ttestchar. testmaxconnect ();
VaR
CLI: tclient;
Begin
Check (charroom. maxclient
For I: = 0 to MaxCount-1 do
Cliarr [I]. Connect ('srv ');
Check (charroom. Count = charroom. maxcount );
CLI: = tclient. Create;
Check (CLI. Connect ('srv') = false );
CLI. Free;
End;
To be continued ....

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.