Chat room to achieve private chat (ii)

Source: Internet
Author: User
Tags array client
Chat room Chat Room program is a application and session object with strong integration of the ASP program. First of all, it is more real-time, chat speed is too slow, then no one will like, and in many people speak at the same time, if the process is not good, it will inevitably occur Zhang Li Dai phenomenon, such as Mingming John said first. Dick said, but the result was reversed. There is also the conversation that each client displays is not synchronized. (Here is a point, chat room The content of Automatic update mode is mainly two, one is the server automatically update, that is, it's chat display content area is an open HTML stream, whenever the server receives the user's conversation will be sent to the user's browser.) The other is that the client periodically sends an update request to the server. The real time of the latter is not strong. But the production is simple, to complete the server-side Automatic Updates, the ASP can not be completed. Because the ASP does not have the built-in latency function. Now the chat room is mainly based on the latter, but the method can also be used in the former.

To address the sequential problems that multiple users speak and display at the same time, you must create a buffer for the conversation, just as the keyboard buffer of the operating system does, even though the system is busy with other tasks, but can still accurately accept user input.

The above procedure example:

Dim chats (20)
For N=1 to 20
Chats (n) =application ("Chats") (n)
Next
is to set up a chats array of 20 elements, then just create a global common counter (saved with the Application object) to indicate that the current content is in that element. Each user also defines a counter for the session object. The information used to record the current chat's native display is displayed on that conversation record. The difference in the conversation must be displayed the next time the content is updated.

The chats array as a conversation buffer is required to be recycled. For example, the first sentence is kept in chats (1), the 20th sentence is kept in chats (20), and the 21st sentence is reused chats (1) to preserve and cover the contents of the first sentence. The chats array is only used to handle public conversation content. It's not a "private conversation." If the private message is saved here as a new piece of information, then the counter will be affected. Because for a chat object that is not a whisper. This sentence is meaningless. In order to reduce the conditions of judgment, the private message with application ("chat") This application of the object variable to save. In the process of whispering, the tiger did not use a buffer, so when the same chat room with a number of netizens at the same time using the private message function, there may be some of the private whispers in not be shown out before the shortcomings are missed, we may wish to play their wisdom to improve OH:

After the chats conversation has been processed. It must be stored back into the global conversation buffer of application ("Chats") (n) so that all users can share the content of the conversation.

The following is a talk to the Whisper deal

' Whisper handle
Application ("chat") = "<font color=blue>" &usertime& "</font> <font color=black>" & username& "</font> <I> quietly to <font color= #00bb00 >" &request. FORM ("Whoto") & "</font> whisper </i>:<font color= #0000aa >" &usersays& "</font><br ><BR> "
' To who say
Application ("Chatto") =request. FORM ("Whoto")
' The man who Speaks
Application ("owner") =username
Session ("chat") = "true"
End If

Session ("Chat") is a mark used to record whether a user has a private message, and when the conversation is updated, it is judged by the tag to determine whether a whisper is generated. While by Applicaton ("chat") to record the conversation, Applicaton ("Chatto") the object of the private message, application ("owner") to save the speaker himself (don't forget to whisper is yourself and the other side of the whisper can see OH: (, Also, when whispering to all (everyone), everyone should be able to see the word.

When the contents of the speech are respectively entered into the application ("Chats") (n) and Applicaton ("chat") the two talk buffers. The next thing to do is to show the content of the conversation. Here first to mention how to achieve a timely chat event Refresh (client initiative)

In the header of our HTML file there is a mark like this

<meta http-equiv= "Refresh" content= "2.5" >

This shows the update class line for the HTML document, which is the one that automatically refreshes the document at 2.5 seconds, so that you can automate the update of the conversation. The ASP file we used to display the dialog is named Top.asp. Let's take a look at the structure of the next section.



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.