How to write a chat

How to write a chat

During an initial stage of distribution of the Internet the only means of text communication in real time were chats. Today they practically disappeared from web. However and now sometimes there is a need to write a chat.

It is required to you

  • - text editor;
  • - locally installed Web server with support of execution of scripts in the selected programming language (for testing).

Instruction

1. Select architecture of future chat. Today there are two basic approaches to development of services of this type: - classical, based on application of frames; - using the AJAX.B equipment the first case functioning of a chat it is based on periodic update of the frame which is built in its main page (the IFRAME HTML-element is usually used). In this frame other static page which is formed on the server when adding by users of messages is loaded. Primary benefits of chats of this kind are: simplicity of implementation, low load of the server, compatibility with the vast majority of browsers, a possibility of work even with the disconnected client scripts. The chats implemented with application the technician of AJAX look more dynamically. Data of the added messages are requested by a client script by means of a XMLHttpRequest object. They come back the server in the XML formats or JSON. Display of messages happens without reset of the page. Advantage of chats of this kind is, as a rule, more friendly interface and a possibility of saving all history of messages within the work session. Decide on type of a chat which needs to be written.

2. Consider possible aspects of implementation of future chat. Solve whether service should support registration and authorization of users. Whether the added messages a long time, etc. should be stored. Select a way of data storage of the last added messages and if it is necessary, information on the registered users. For the solution of all these tasks it is possible to use the database. However, considering specifics of chats, usually is enough text or XML files.

3. Implement the mechanism of display of the interface of a chat and output of messages to the user. If frames are used, it is enough to write a server script of forming of the page depending on the status of the user saved by means of the mechanism of sessions. Or just to create the static page if the chat does not support authorization. The interface of the chat using AJAX can be formed by client scripts completely. For development of these scripts it is expedient to use frameworks, such as Prototype (prototypejs.org), script.aculo.us and Google Web Toolkit (code.google.com/webtoolkit/).

4. Write a server script of adding of messages. It should take these forms or the XML-request transferred from the user's browser, to check correctness of information, to update the list of messages and if it is necessary, to form the HTML-file used for display of the current contents of a chat on its basis.

5. If necessary write separate scripts for implementation of registration of users in a chat and their authorization.

Author: «MirrorInfo» Dream Team


Print