The chat room program is an Asp program with strong combination of application and session objects. First of all, it is more real-time and the chat speed is too slow, so no one will like it. Moreover, when multiple people speak at the same time, if the program is not handled well, it is inevitable that the phenomenon of Zhang Guan Li Dai will occur, such as explaining what Zhang San said in the Ming Dynasty first. What Li Si said was behind, but the result was reversed. Also, the conversation content displayed by each client is not synchronized. (I emphasize here that there are two main ways to update the conversation content in the chat room. One is the server automatically update, that is, its chat display content area is an open html stream. Whenever the server receives the user's conversation content, it will be sent to the user's browser. The other is that the user side regularly issues update requests to the server side. The latter is not as real-time as the former. But it is simple to make. To complete the automatic update on the server side, it cannot be completed by asp alone. Because ASP does not have a built-in delay function. The chat room mentioned in the examples are mainly explained by the latter, but the method can also be used in the former)
To solve the problem of the order in which multiple users speak at the same time and display it, it is necessary to create a buffer for the conversation content, just like the function of the operating system's keyboard buffer. Even if the system is busy dealing with 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)
next
It is to create a 20-element chats array, and then you only need to create a global common counter (save with the application object) to indicate which element the current latest speech content is in. Each user defines a counter for the session object. The information used to record the current chatter's local display is displayed on which conversation record. The content of the conversation between the two must be displayed the next time the speech is updated.
The chats array is used as a conversation buffer and needs to be used in a loop. For example, the first sentence is saved in chats(1), the twenty-first sentence is saved in chats(20), and the twenty-first sentence is reused to save chats(1) and overwrite the content of the first sentence. The chats array is only used to handle public conversation content. That is, it is not a "whisper". If you save the whisper here as a new information, it will affect the counter. Because for chat subjects who are not whispering. This sentence is meaningless. In order to reduce conditional judgment, the whisper is also saved using the application object variable application ("chat"). When dealing with whispers, Xiaohu does not use a buffer. Therefore, when multiple netizens use the whisper function at the same time in the same chat room, there may be a disadvantage of missing whispers before they are displayed. You might as well use your wisdom to improve it:)
After processing the chats' conversation content. It must be restored in the global conversation buffer application("chats")(n), so that all users can share the conversation content.
Below is a conversation about whispers
'Whispering processing
application("chat")="<font color=blue>"&usertime&"</font> <font color=black>"&username&"</font> <I>Silently whispered to <font color=#00bb00> "&("whoto")&" </font>:<font color=#0000aa> "&usersays&"</font><BR><BR>"
'To whom
application("chatto")=("whoto")
'The speaker
application("owner")=username
session("chat")="true"
end if
session("chat") is a tag used to record whether the user has whispers. When updating the conversation content, it is determined by judging whether there is whisper. at the same time. Record the conversation content through applicaton("chat"), apply ("chatto") to whisper, application ("owner") save the speaker himself (don't forget that whispers can be seen by yourself and the other party who receives whispers: (And, when whispering to ALL (everyone), everyone should be able to see this silly sentence.
When the speech contents enter the two conversation buffers of application("chats")(n) and application("chat"). The next step is to display the conversation. Here we will first mention how to realize the timely refresh of chat events (client proactively)
There is a tag like this in the header of our html file
<meta http-equiv="refresh" content="2.5">
Here is the update class line of the html document. The above mark is to automatically refresh this document at a speed of 2.5 seconds. Then, using this point, you can automatically update the conversation content. The asp file we use to display the conversation is. Let’s take a look at its structure in the next section.
Previous page1234Next pageRead the full text