Sockets - Study Mode
[#1] Which of the following is a stateless protocol?
Correct Answer
(C) HTTP
Explanation
Solution: HTTP is a stateless protocol. A stateless protocol does not require the server to retain information or status about each user for the duration of multiple requests.
[#2] What does the value 2 of the WebSocket attribute Socket.readyState indicate?
Correct Answer
(B) Handshake connection
Explanation
Solution: The readonly attribute readyState represents the state of the connection. It can have the following values: 1. A value of 0 indicates that the connection has not yet been established. 2. A value of 1 indicates that the connection is established and communication is possible. 3. A value of 2 indicates that the connection is going through the closing handshake. 4. A value of 3 indicates that the connection has been closed or could not be opened.
[#3] How many WebSocket events are available?
Correct Answer
(C) 4
Explanation
Solution: There are fourWebSocket events namely : 1. open 2. close 3. message 4. error
[#4] Which method is used to close the WebSocket?
Correct Answer
(B) Socket.close()
Explanation
Solution: The Socket.close() is used to close the WebSocket.
[#5] How does the client and the server communicate following the rules defined by the WebSocket protocol?
Correct Answer
(A) Long-lived TCP Socket
Explanation
Solution: The client and server communicate over a long-lived TCP socket following rules defined by the WebSocket protocol.