WebSocket Personal Comprehension Summary

Source: Internet
Author: User
Tags money back

WebSocket
    • Interpretation: chat rooms, services, sockets, Protocols
    • references: https://www.ibm.com/developerworks/cn /web/1112_huangxa_websocket/index.html

      As a next-generation Web Standard, HTML5 has many compelling new features, such as Canvas, local storage, multimedia programming interfaces, We Bsocket and so on. The WebSocket, which has the "Web TCP", is particularly appealing to developers. The advent of WebSocket makes it possible for the browser to provide support for sockets, providing a two-way, TCP-based connection between the browser and the server. Web developers can easily use WebSocket to build real-time web applications, and in the hands of developers there is a more powerful weapon of divine soldiers. The

    • websocket Protocol is a persistent protocol, relative to HTTP, a non-durable protocol.
      Simply say: http1.0, a request corresponds to a response, when the end of the visit
      http1.1, multiple request for multiple response, using Keep-alive;
      Always: A req can only correspond to a res, and this res can not be actively sent to the client, it is passive. Yes, very passive. And, HTTP is a stateless protocol, once the request is over, it will forget everything about the request, and then wait for your next request, you have to re-recognize it, resend the request, it again to calculate the results for you and return to you.
    • live Web application
      Normal Web request communication process

1. Questions: such as online games, online securities, device monitoring, news online, RSS feeds, etc., when the client browser is ready to render this information, the information may be outdated on the server side.
2. [Previous solution][3]
1) Ajax polling: Front-end set a timer, every time, to send a request to the server, and then the server to you back, keep asking, the server keeps going back, the final result, Server weaknesses, it is the collapse!
2) long poll (long polling): This is the same mechanism, but the blocking model is taken. Client to the server to borrow money, the server did not pay, said is to work to earn money, and so on to pay him, but the client does not go, wait until the server to take the money back to go, or the client is too long, has exceeded its set waiting time, it will end the task of borrowing money, and then some time, come and see The server is not already rich. If it is, the client constantly and the server for money, to come, take it, and then to take a trip, away, then this method and Ajax polling no difference. Terminology: When there is no data update on the server side, the connection is maintained for a period of time until the data or state changes or time expires, and this mechanism reduces the interaction between invalid client and server

    • Simple summary: (if wrong please point out)
      1. High performance: Why the performance is high, because the client as long as the request, the connection, no longer request, waiting for the server to actively give the client data: [the scenario is as follows][3]:
      Client: La LA, I want to set up the WebSocket protocol, required services: Chat,websocket protocol version: + (HTTP Request)
      Server: OK, confirm, upgrade to WebSocket protocol (HTTP protocols switched)
      Client: Please push it to me when you have information.
      Server: OK, sometimes I will tell you.
      Service side: Updated
      Service side: Updated again
      Service side: ha haha haha ah haha haha
      Service side: Laughing at me ha ha haha haha
      So why would he solve the problem of consuming resources on the server? In fact, we use the program is to go through two layers of proxy, that is, HTTP protocol in Nginx and other servers, and then sent to the corresponding handler (PHP, etc.) to deal with. In short, we have a very fast operator (Nginx) who is responsible for handing over the problem to the appropriate customer service (Handler). The operator itself is basically the speed is enough, but each time is stuck in customer service (Handler), the old customer service processing speed is too slow. , resulting in insufficient customer service. WebSocket solves such a problem, after the establishment, can directly with the operator to establish a persistent connection, there is information when customer service to find ways to inform the operator, and then the operator in the unified transfer to the customer. This will solve the problem of customer service processing speed too slow
      [3]:https://www.zhihu.com/question/20215561
      2. Bidirectional: The server can also proactively send data to the client, no longer is the client kick a foot should be a sound state
      3. Compatibility: Can be compatible to ie10+,chrome4+,firefox4+,opera10+,safari5+
      4. Can cross-domain (Socket.io)
Socket.io
    • Interpretation: [Socket.io is a framework for real-time bidirectional communication, which is essentially based on WebSocket technology. Socket.io compared to other webSocket communication-based libraries such as WS, the benefit is that when the browser supports WebSocket technology, it works normally with WebSocket, and when the browser does not support WebSocket, it can degrade smoothly into polling for work. 4]
      [4]:http://www.cnblogs.com/ghost-xyx/p/7060070.html
    • Socket.io a set of APIs for both [client][5] and [Server-side][6]
      [5]:https://socket.io/docs/client-api/
      [6]:https://socket.io/docs/server-api/

WebSocket Personal Comprehension Summary

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.