Training Guide: Programming in HTML5 with JavaScript and CSS3 Ebook

(Nora) #1

436 CHAPTER 10 WebSocket communications


Answers


This section contains the answers to the lesson review questions in this chapter.

Lesson 1



  1. Correct answer: C
    A. Incorrect: The onopen event is triggered when the connection is opened.
    B. Incorrect: The onclose event is triggered when the connection is closed.
    C. Correct: The onmessage event is triggered when data is received.
    D. Incorrect: The onerror event is triggered when an error is thrown.

  2. Correct answer: B
    A. Incorrect: SignalR does not work with Node.js websites.
    B. Correct: The Socket.IO library works with Node.js to provide a browser-
    independent library for WebSocket communications.
    C. Incorrect: FarmSockets does not exist.
    D. Incorrect: AgnosticSocket does not exist.

  3. Correct answer: B
    A. Incorrect: If you wait until the connection is closed, you will need to create a new
    WebSocket object.
    B. Correct: You can add code to send empty messages periodically.
    C. Incorrect: There is no keepAlive property on the WebSocket object.
    D. Incorrect: If you create a new WebSocket object each time you send a message,
    the server will think that new browsers are communicating with it.

Free download pdf