Overview IE and SQL2K develop an XML chat program

Source: Internet
Author: User
Tags array object datetime sql client
sql|xml| Program | chat

Years of competition between different browsers have resulted in many tools that help developers accomplish tasks that were difficult to do before. Now, with just a little script, you can create an application that binds data to the user control, so that you can communicate with the server through a built-in proxy type of control.

In Internet Explorer (IE), these things include XML data islands and XMLHTTP objects, XML data islands to bind data to form elements, and XMLHTTP objects to create synchronous and asynchronous calls to the server without navigating to other pages within the current page. I will use these two easy-to-use features to create a simple chat application consisting of a number of ASP pages that act as UI, JavaScript for client-side functionality, and a T-SQL that completes business logic in 2000.

The client and the server use XML communication. After the WEB server receives a message block, the message block is appended to a timestamp-MESSAGES table in SQL Server. Based on predefined intervals, the customer requests updates from the server, including the list of messages and online users that have been appended to the database since the last request for information from the server.

The customer will send a <action/> to the server via the XMLHTTP object. Action is either a request to refresh the message and the user list, or to send a new message. These actions are saved in a table called actions. The server responds to the request or accepts a new message and appends it to the MESSAGES table.

When the server responds to a request for a message, it returns a list of all new messages since the last request. To keep track of the customer's activities, I use an activity table that contains the date and time (datetime) of the customer's activities, and the customer's identity is saved in the table HANDLES, and the table's name is intuitive.

Here is the script to build the table:

CREATE TABLE [dbo]. [ACTIONS] (
[ACTION_ID] [INT] IDENTITY (1, 1) not NULL,
[Action_name] [varchar] (m) NULL,
[ACTION_DESCR] [varchar] (255) NULL
) on [PRIMARY]
Go

CREATE TABLE [dbo]. [Activity] (
[HANDLE_ID] [INT] Null
[Action_time] [DateTime] Null
) on [PRIMARY]
Go

CREATE TABLE [dbo]. [HANDLES] (
[HANDLE_ID] [INT] IDENTITY (1, 1) not NULL,
[Handle] [nvarchar] (a) NULL
) on [PRIMARY]
Go

CREATE TABLE [dbo]. [MESSAGES] (
[msg_id] [INT] IDENTITY (1, 1) not NULL,
[Message] [nvarchar] (255) NULL,
[ACTION_ID] [INT] Null
[Action_time] [DateTime] Not NULL
) on [PRIMARY]

All data operations are done through the stored procedure. All data interfaces will be completed through a generic COM that acts as a liaison between the WEB server and SQL Server 2000. COM object exposes a method runspreturnstream that I want to use. The first parameter of the method is the name of the stored procedure, and the second parameter is an array of parameter arrays. A parameter array is a simple array of the following formats: (Paraname, Paramtype, Paramlength, paramvalue). Paramtype is one of the ADO Parameter Type enumerations. An ASP page is responsible for accepting actions and creating responses, which I call handleaction.asp.

The chat page will contain an area to display the chat message, and this area is a TABLE containing the DIV. This table is bound to a xmlmessages XML data island. Another area shows the current user; The area is also a table contained in a DIV that is bound to a xmlusers XML data island. There is also a TEXTAREA for users to enter messages.


-----------------------------------------------------------------
The author of this article: Phillip Perkins is Ajilon Consulting's contract holder. He has a wealth of experience from machine control and client/server to intranet applications.



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.