How To Write A Chat

Table of contents:

How To Write A Chat
How To Write A Chat

Video: How To Write A Chat

Video: How To Write A Chat
Video: How to Write in Chat in Apex PS4 2024, May
Anonim

In the early days of the Internet, chats were the only means of real-time text communication. Today they have all but disappeared from the web. However, even now sometimes it becomes necessary to write a chat.

How to write a chat
How to write a chat

It is necessary

  • - text editor;
  • - a locally installed web server with support for executing scripts in the selected programming language (for testing).

Instructions

Step 1

Choose the architecture of the future chat. Today, there are two main approaches to the development of services of this type: - classic, based on the use of frames; - using the AJAX technique In the first case, the functioning of a chat is based on periodic updating of a frame embedded in its main page (usually an HTML IFRAME element is used). This frame is loaded with another static page, which is generated on the server when users add messages. The main advantages of chats of this type are: simplicity of implementation, low server load, compatibility with the vast majority of browsers, the ability to work even with disabled client scripts. Chats implemented using AJAX techniques look more dynamic. The added message data is requested by the client script using an XMLHttpRequest object. They are returned by the server in XML or JSON format. Displaying messages occurs without reloading the page. The advantage of chats of this type is, as a rule, a more user-friendly interface and the ability to save the entire history of messages within the work session. Decide on the type of chat you want to write.

Step 2

Consider possible aspects of the future chat implementation. Decide if the service should support user registration and authorization. Whether the added messages are to be stored for a long time, etc. Select the way to store the data of the last added messages and, if necessary, information about the registered users. A database can be used to accomplish all of these tasks. However, given the specifics of chats, text or XML files are usually sufficient.

Step 3

Implement a mechanism for displaying the chat interface and displaying messages to the user. If frames will be used, it is enough to write a server-side script for forming a page depending on the user's status, which is saved using the session mechanism. Or just create a static page if the chat does not support authorization. The chat interface using AJAX can be completely rendered by client-side scripts. To develop these scripts, it is advisable to use frameworks such as Prototype (prototypejs.org), script.aculo.us, and the Google Web Toolkit (code.google.com/webtoolkit/).

Step 4

Write a server-side script for adding messages. It should accept form data or an XML request sent from the user's browser, check the correctness of the information, update the list of messages and, if necessary, generate an HTML file based on it, which is used to display the current chat content.

Step 5

If necessary, write separate scripts to implement user registration in the chat and their authorization.

Recommended: