Built your own chat room with ASP

xiaoxiao2021-03-06  19

Chat room wants you must have to go, but don't want to build your own chat room? In fact, this is not difficult. Active Server Script provides an Application object and a session object. The Application object represents an Active Server application, which is a web page. The session object represents a user, representing a user's access to this page. Through Application objects, all user sharing information can be accessed, and the data can be done while the web server is running, and the session object can also maintain data from the user's access, and use these two objects. It is very convenient to build your own CHAT app.

---- One, Application object:

---- 1. Property: Application object does not have built-in properties, but users can define their properties:

---- Application ("Property Name") = value, once the property is assigned, it will always exist until the web server closes the service, and it can be read by all users, so you can use it to send a conversation between users. content.

---- 2. Method: When two users simultaneously writes the value of the Application attribute, one party modification is directly covered by the other operation, in order to avoid this, the user can call the Lock method to lock, so only The current user can operate the properties of the Application, and the UNLock method unlocks after the user completes the operation, so that other users can also modify the properties of the Application.

---- 3. Event: Creating an Active Server application requires the Global.asa file to create a Global.asa file on the web server, which contains an event handler for Application objects and session objects, usually, Application_onstart events are used to define properties of the application level. .

---- II. Create a CHAT application: The program is running as shown in the following figure (omitted)

---- 1. Set the variable of the application: You need to create two application-level variables, gchars array is used to store the user's conversation content, GCUNTER uses the counter, the control page is displayed, here we let the page display the most recent 10 lines Conversation. These variables must be initialized when the application starts, so they are created in the Application_onstart event in the global.asa file: