Chat room self Follow Me (turn)

Source: Internet
Author: User
The internet has not been to the chat room of people, is very rare, below, we will make a simple chat room.
There are usually two ways in which a chat room displays a conversation. One is to refresh the entire dialog display area every x seconds, the disadvantage of this side is obvious: large data transmission and the screen has a flicker; second, there is a new speech, the content is passed to the client, and added at the end of the original dialogue, this method of data transmission is relatively small and the screen is smooth scrolling, good visual effect. The implementation of the first method already has a lot of information to introduce, so this article describes the second way to refresh.
Design ideas:
The ⑴ server side only retains the latest 30 statements as a buffer, and the new speeches will squeeze out the oldest speeches.
⑵ each sentence is assigned an incremented ordinal number. The number of statements that the client last appears is recorded in the session.
⑶ use the hidden frame for refreshing, refresh, compare the session value to the number of each statement in the buffer, and if the ordinal is greater than the session value to indicate that the statement is new, take the statement's data out and assign the statement's ordinal value to the session.
When the ⑷ dialog display area is opened with Document.open (), it is no longer closed, and when new data is fetched and uploaded to the client when the hidden frame is refreshed, the raw data is formatted for display (this work can be performed on the server side, but to ease the burden on the server, Transfer the synthesis of the conversation to the customer, and then call the Document.writeln method to write the contents of the speech to the end of the dialog display area.
⑸ in the dialog display area to place a section of automatic scrolling code, so that the screen automatically scroll down, and through the check box of the speech area to choose whether to automatically scroll.
Implementation method:
One, this procedure only needs 4 files to realize:
⑴chat.asp: Chat Room frame file, responsible for initializing the program operating environment and randomly allocate four digits as user name, then the page from top to bottom into four parts, top and bottom two frame height of 0.
⑵chatfyq.htm: Speaking area, providing a text box for entering names, statements, and a spoke button and an automatic scrolling switch (check box), and defining Javascript:checksays () performed on the client (validity detection of statements), CLS () (Empty the contents of the dialog display area), write () (Initialize dialog display area, define page color, text size, and place scrolling code), SW (username) (when clicking on the name in the conversation area, write the name to the speaker box), W (UN,SA,TN,DT) (Combine the original data into a complete statement and add it to the end of the dialog display area).
⑶chatt.asp: This file is located at the top of the hidden frame (height 0) in a timed refresh, the new statement of raw data used <script LANGUAGE=JAVASCRIPT&GT;PARENT.F2.W ("name", "Speech content", "original name" , "Speak Time") </script> format output to the client, you can invoke the chatfyq.htm defined in the W (UN,SA,TN,DT) function to display the speech content.

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.