[0-1] developed from scratch instant web chat application

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/ET1131429439/article/details/102748646

To achieve real-time web chat system

The first page [0]

Foreword

The project is how I learn to university for three years to carry out a test of what. In the first, to write the blog recorded pit project development process and problems encountered, the second is to be able to find a novice in the long fragmented knowledge inside a guide book to know ((╯ `□ 'general direction) ╯ ~ ╧╧ certainly not say that I was right). I will update more slowly from the beginning, because I was feeling the way across the river. As to the use of knowledge, I will mention their relevant knowledge of the technology when needed. Blog is often modified, I want it as my laptop, to fill the vacancy by modifying the knowledge, experience became one of my books.

Background of the project

Live chat system [Instant Messaging], can think of very famous QQ, micro letter this type of client application. There have previously QQ web version, out of service since January 1, 2019, comes in the presence of micro-channel web version. Ever since, I wanted to write a similar application, web-based end instant chat system, can achieve real-time chat, interactive online, offline message function. I think the generic nature of the system is very high, can be mounted on any desired chat message function of the project. After all, in today's social software usage can be described as unprecedented high.

Design ideas

A little summarize data

Early communication software QQ is based on TCP / IP protocols. Chat communication using UDP protocol, the way transit through the server. As we all know, UDP protocol is not reliable, although the agreement, just send it, no matter if it was received, but its transmission is very efficient.

Here's TCP / IP according to Baidu Encyclopedia TCP / IP protocol _ Baidu Encyclopedia wrote in explanation of his

TCP / IP (Transmission Control Protocol / Internet Protocol, Transmission Control Protocol / Internet Protocol) refers to the protocol suite enables transmission of information between multiple different networks. TCP / IP protocol refers not only TCP  and IP two protocols, but a means of the FTP , the SMTP , TCP, the UDP protocol cluster configuration, IP and other protocols, just as the TCP / IP protocol in the TCP and IP protocol the most representative, it is called TCP / IP protocol.

And that this is the QQ desktop software to network communication protocols, and our web side is to use HTTP (a protocol defined in the application layer, their relationship can own Baidu)

HTTP is a simple request - response protocol , which typically runs on top of TCP. It specifies the client may send a message to the server, and what kind of response obtained. Request and response message header given in the form of ASCII codes; and the message content having a MIME format similar. This simple model is the early success of Web meritorious, because it makes the development and deployment is so straightforward.

Where the request and response systems for the web chat is the most important step, and I will be 11 later to explain why the request and response would be an important step?

Because any web application will escape this step is not open, C / S client - server architecture is to build the current network application (B / S Browser - server architecture is a special c / s structure) basic mode of operation, the client by requesting such from the server to obtain the desired data. 

Here , will know, in fact web live chat system with other web applications on the underlying realization of ideas is no different.

I.e., the core idea: after (message packaging, unpacking, filtered, save, forward) A user sends a message to the server, the server forwards the message to a series of processing user B (or population).

Instant messaging program

Now 9012 years, we still look relatively new technology now, the program has achieved roughly about four kinds of this chapter] [0-1] only a simple introduction. For details, please see a future article

  1. ajax poll
  2. ajax long polling
  3. web-socket connection length
  4. server-send-event (with the program information online rarely)

ajax ajax long polling and the polling is HTTP-based, either one by itself flawed: Polling requires faster processing; long polling is more capacity to handle concurrency requirement; both are "passive Server" It reflects: the server does not actively push information, but transmits in response returned by the client after ajax request.

HTML5 WebSocket is a protocol provided by the start of full-duplex communication over a single TCP connection, such WebSocket data exchange between the server and the client easier. webSocket initiative allows the server to push data to the client. Different from the conventional http protocol, the protocol can realize full duplex communication between the server and the client. In simple terms, you first need to establish a connection between the client and server side, this part needs to http. Once the connection is established, the client and server on an equal footing, can send data to each other, the difference between the request and response does not exist.

SSE is HTML5 new features, called Server-Sent Events. It can allow a service to push data to the client. SSE at inherently long before polling, different short poll, though they are based on http protocol, but polling requires the client to send the request. The SSE biggest feature is no client sends a request, the server can be achieved as long as the data is updated, it can be sent immediately to the client.

This "proactive" compared to "passive" of superior performance.

 

 

 

[2019-10-25]

Guess you like

Origin blog.csdn.net/ET1131429439/article/details/102748646