What is HTML5 WebSocket, Long/short Polling, AJAX, WebRTC, Server-Sent Events?



  • I've decided to make a bike, a little chat for friends. I was wondering, how is this going to be like a concussion or other projects? The messages/notifications come instantly and do not require the user to manually update or forcibly rephrase the page.

    I've been looking and stumbling about what I used to do: Ajax a searchlight at the request server at equal short intervals to get an answer... There is. long/short polling♪ I caught them at first, but in the search, I ran into them. HTML5 websockets♪ I think he's a cop in the field.

    Everyone, to some extent, does one thing, but I don't know what their difference is? How do they work? I'd like to know at least briefly how they work to make use of a technique, depending on the situation. Or go on. HTML5 WS And don't you?



  • WebSockets, in fact, new technology. Long polling is a circumferential and dirty manoeuvre to prevent a new connection to each new request, as AJAX does. But long polling was created when the WebSockets didn't exist at all. And the technologies are developing, they're evolving, and now they're getting popular.

    My little self-responsive recommendation: reading and reading it. http://caniuse.com/#feat=websockets ♪

    But still.

    how different methods of communication work on the Internet:

    • AJAXзапрос , ответ♪ Creates a connection to the server, sends the titles of the request with some data, receives a response from the server, closes the connection. Requests are often sent. Supported in all major browsers

      It's like, just realise, the data can be downloaded.

      Like a minus: too many unnecessary requests (this must be the main minus :-)). There are also significant delays between data creation and receipt. Server sends data not when they came in, but when a new request comes in.

    • Long pollзапрос , ожидание , ответ♪ Creates a server as AJAX, but leaves the connection open for some time (not much). Silver Not at all. Respond to the information requested and awaits new information. While the connection is open, the client is waiting for the data from the server. Once there's something new on the server, he's sending her to her client. The client has received new information, or if the waiting time has expired, has sent another request to the server by launching the waiting process again. Usually, the compound is reset from 20 to 30 seconds (for example, 29 seconds) to avoid possible problems, such as HTTP-proxi. Supported in all major browsers

      Plus: small number of requests (compared to conventional AJAX to)

    • WebSocketsклиент сервер♪ A TCP connects with the server and remains open as required. Server or client can easily close it. In connection, there are so-called " rustration " , i.e. the client sends special headings that encrypt the base64. If the server likes everything, he'll return the title Accept. It should be remembered that the client engagement will always have a headline. Originwhich will be sent to the server, they want to receive clients from different sources or not. Once the server and client are installed, they can send messages to each other when new information is available (or on the server or on the client) in both directions at any time. This is very effective if the annex requires frequent data exchange in both directions. Also, the data sent from the client to the server are somewhat encrypted. One more plus.
      http://caniuse.com/#feat=websockets (sighs)It's pretty good.)

    • WebRTC (Web Real Time Communication - real-time web communication) - peer peer (P2P equal to equal). Transport to link customers (two or more) through which conventional data and media flows can be transmitted. UDP, TCP and even more abstract layers are used. This is generally used to transfer large volume data, such as median data (audio and video). Both sides (pires) may transmit data independently. http://caniuse.com/#feat=rtcpeerconnection (sighs)medium support)

    • Server-Sent Eventsклиентсервер♪ The client shall establish a permanent and long connection with the server. Only the server can send the data to the client. If the client wants to send something to the server, it'll have to use other technology/protocol. This HTTP protocol is simple in most server platforms. This is a preferred protocol for use than Long Polling. http://caniuse.com/#feat=eventsource (IE as always in the backwards)

    Benefits:

    Each way has its advantages and its minus. However, WebSockets are now considered good and promising. Major advantage WebSockets For the server, this is not a HTTP request, but a communication protocol itself. This allows for the enormous benefits of productivity and architecture. For example, in node.js, the same memory can be divided for different juket compounds, thus gaining access to general variables. So you don't need to use the database as a exchange point in the middle (as with AJAX or Long Polling and, for example, PHP). You can store data in operational memory... ♪

    It's up to you to use, of course.


    Response translated, slightly modified and supplemented with https://stackoverflow.com/a/10029326/6104996




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2