Use ASP to build your own chat room

Source: Internet
Author: User
You must have been to the chat room, but do you want to create your own chat room? In fact, this is not difficult. Active Server Script provides the Application object and Session object. The Application object represents an Active Server Application, that is, a Web page, and the Session object represents a user, represents a user's access to this page. The Application object allows all users who access this page to share information and persistently save data during the running of the Web server, the Session object can also maintain data permanently during a user's access. Using these two objects, you can easily build your own Chat application.
---- 1. Application object:
---- 1. Attributes: the Application object does not have built-in attributes, but you can define your own attributes:
---- Application ("Property Name") = value. Once an attribute is assigned, it will exist until the Web server closes the service and it can be read by all users, therefore, you can use it to send conversation content between users.
---- 2. method: when two users write the value of the Application attribute at the same time, the modification of one party is directly overwritten by the operation of the other party. To avoid this phenomenon, you can call the Lock method to Lock the Application, so that only the current user can operate on the attributes of the Application. After the operation is completed, the user calls the Unlock method to Unlock the Application, so that other users can also modify the attributes of the Application.
---- 3. event: to create an Active Server application, you must create Global under the virtual home directory where the application is stored on the Web Server. the asa file contains the event processing routines of the Application object and Session object. Generally, Application_Onstart events are used to define Application-level attributes.
---- 2. Create a Chat application: as shown in the following figure (omitted)
---- 1. set application variables: two application-level variables need to be created here. The gchars array is used to store the user's conversation content. gcounter is used as a counter to control the number of lines displayed on the page, here, we can display up to 10 most recent conversations on the page. These variables must be initialized when the application starts, so they must be created in the Application_onstart event in the Global. asa file:
<Script language = "vbscript" runat = "server">
Sub application_onstart ()
Dim lchars (10)
Application ("gchars") = lchars
Application ("gcounter") = 0
End sub
</Script>
---- 2. determine how to process ASP: when the user requests the ASP file for the first time, the GET method is used. Then, when the user inputs the conversation content and submits the file, the POST method is used, here, the form is submitted to itself, so this ASP file will be requested again. We passed the test Request. serverVariales ("Request_Method") variable to determine the file Request method: IF Request. serverVariales ("Request_Method") = "POST" then
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.