Web Technology Basics

A chat app needs to deliver new messages from the server to the browser immediately. Which of the following correctly describes WebSocket?

  1. AA method in which the browser sends an HTTP request every few seconds and asks the server each time whether new messages have arrived
  2. BIt switches a connection started with HTTP (an upgrade) so that either the server or the browser can send messages over that one connection
  3. CA method in which, when an event occurs, a server notifies another server's pre-registered URL with an HTTP POST request
Show answer and explanation

Answer: B. It switches a connection started with HTTP (an upgrade) so that either the server or the browser can send messages over that one connection

WebSocket asks for Upgrade: websocket in an HTTP request, and when the server returns 101 Switching Protocols, the same TCP connection is switched to WebSocket communication. After that the connection is kept open, and either the server or the browser can send small messages with little overhead. With a method that asks at fixed intervals, requests occur even when there is nothing new, and new messages are delayed by up to the interval between checks. Notifying from server to server with an HTTP POST is called a webhook.

  • A. This is a method of asking periodically (polling). Requests occur even when there is nothing new, and delays of up to the interval arise.
  • B. Correct. The connection stays open, and messages can be sent in both directions at any time.
  • C. This describes a webhook. It is used for notifications between servers.
Practice this topic Back to topic

Books on Web Technology Basics Ad

As an Amazon Associate I earn from qualifying purchases.

More Web Technology Basics questions

  1. A merchant's server wants to know immediately when a payment is completed on an online payment service. Which of the following correctly describes the method in which the payment service sends a notification by HTTP POST to a URL the merchant registered in advance (a webhook)?
  2. Which of the following correctly describes the DOM (Document Object Model) used in browsers?
  3. For the element styled with the CSS above, which of the following is the width from the outer edge of the left border to the outer edge of the right border?
  4. Assume there are no other style specifications. In the HTML above, which of the following is the color of the text "Hello"?
  5. In the processing a browser does before showing the first screen (the critical rendering path), a <script src="app.js"> written without attributes inside <head> makes the HTML parser stop at that point. Which of the following correctly describes the behavior when the defer attribute is added to this element?