Implement the chat room whispering function (medium) (Post)
Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
The chat room program is an asp program with strong application and session object combination. First of all, it is relatively real-time, chat speed is too slow, so no one will like it, and when many people speak at the same time, if the program does not handle well, it is inevitable that Zhang Guanli Dai will occur, for example, what James said first. After Li Si said something, the result was reversed. In addition, the conversation content displayed on each client is not synchronized. (Here, we emphasize that there are two ways to automatically update the conversation content in the chat room. One is to automatically update the conversation content on the server, that is, the chat display content area is an html stream being opened, each time the server receives the user's conversation content, it will be sent to the user's browser. The other is that the client regularly sends an update request to the server. The latter is less real-time than the former. However, it is easy to create. To complete automatic updates on the server, asp alone cannot be used. Because ASP does not have the built-in latency function. Now the example of the chat room is mainly explained by the later, but the method can also be used in the former)
To solve the problem of the order in which multiple users speak and display at the same time, you must create a buffer for the conversation content, just as if the keyboard buffer function of the operating system is the same, even if the system is busy processing other tasks, it can still accept user input accurately.
The above program example:
Dim chats (20)
For n = 1 to 20
Chats (n) = application ("chats") (n)
Is to create a chats array with 20 elements, then you only need to create a global common counter (which is saved using the application object ), it is used to indicate that the latest speech content is in that element. Each user defines a counter for the session object. The information used to record the current chatbot display on the machine is displayed on that conversation record. The difference between the two must be displayed in the next update.
The chats array is used repeatedly as a talk buffer. For example, the first sentence is saved in chats (1), the second sentence is saved in chats (20), and the second sentence is saved using chats (1) again, overwrite the content of the first sentence. The chats array is only used to process public conversation content. Is it "whisper"? If you save the whisper as a new message here, it will affect the counter. Because for non-whispering chat objects. This sentence is meaningless. In order to reduce the condition judgment, we will also use the application object variable application ("chat") to save it. Xiaohu does not use the buffer zone for Whisper processing. Therefore, when multiple users in the same chat room use the whisper function at the same time, some whispers may appear before they are displayed, we may wish to use our own wisdom to improve the shortcomings we have missed :)
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to firstname.lastname@example.org. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
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:
and provide relevant evidence. A staff member will contact you within 5 working days.