What is the main purpose of WebSockets in ASP.NET applications?
A. To enable full-duplex communication channels over a single TCP connection
B. To perform server-side rendering
C. To handle form validation
D. To manage user authentication
Answer: A
Which protocol does WebSocket use to establish a connection?
A. HTTP for the initial handshake and then switches to WebSocket protocol
B. FTP
C. SMTP
D. POP3
Answer: A
How do WebSocket connections compare to traditional HTTP connections?
A. WebSocket connections are persistent and allow bidirectional communication, while HTTP is unidirectional and stateless
B. HTTP connections are persistent and allow bidirectional communication
C. WebSocket connections are temporary and only support unidirectional communication
D. HTTP and WebSocket connections are identical in functionality
Answer: A
Which HTTP method is used to initiate a WebSocket connection?
A. GET
B. POST
C. PUT
D. DELETE
Answer: A
How does a WebSocket server confirm the establishment of a connection?
A. By sending a WebSocket handshake response
B. By sending an HTTP status code 404
C. By closing the connection
D. By redirecting to a new URL
Answer: A
What is the default port for WebSocket connections?
A. 80 for non-secure and 443 for secure connections
B. 21
C. 25
D. 110
Answer: A
In ASP.NET, which class is used to create a WebSocket server?
A. System.Net.WebSockets.WebSocket
B. System.Web.Http.WebSocket
C. System.Net.Sockets.Socket
D. System.Web.WebSocket
Answer: A
Which method is used to send a message through a WebSocket connection in ASP.NET?
A. SendAsync()
B. PostAsync()
C. WriteAsync()
D. Transmit()
Answer: A
What is a common use case for WebSockets in web applications?
A. Real-time data updates and interactive communication
B. Handling file uploads
C. Performing server-side processing
D. Managing session state
Answer: A
Which WebSocket class method is used to close the connection?
A. CloseAsync()
B. Disconnect()
C. Terminate()
D. Shutdown()
Answer: A
How does WebSocket handle message fragmentation?
A. By allowing messages to be sent in multiple frames
B. By sending entire messages in one frame
C. By using separate WebSocket connections for each fragment
D. By compressing messages
Answer: A
What is the primary advantage of using WebSocket over long polling?
A. WebSocket provides lower latency and reduces server load by maintaining a persistent connection
B. Long polling provides faster data transfer speeds
C. Long polling requires fewer server resources
D. WebSocket is easier to implement than long polling
Answer: A
Which HTTP header is used to initiate a WebSocket connection?
A. Upgrade
B. Content-Type
C. Authorization
D. Accept
Answer: A
How can you handle WebSocket messages in ASP.NET Core?
A. By using the WebSocketHandler
class in the middleware
B. By using HTTP controllers
C. By using SignalR
only
D. By using HttpClient
Answer: A
Which class in ASP.NET Core represents a WebSocket connection?
A. WebSocket
B. HttpContext
C. HttpClient
D. Socket
Answer: A
What type of data can be transmitted through WebSocket connections?
A. Text and binary data
B. Only text data
C. Only binary data
D. Only HTTP headers
Answer: A
What is the purpose of the WebSocketOptions
class in ASP.NET Core?
A. To configure WebSocket options such as buffer size and connection timeouts
B. To handle WebSocket message encoding
C. To manage WebSocket connections
D. To authenticate WebSocket requests
Answer: A
Which method in the WebSocket
class is used to receive data?
A. ReceiveAsync()
B. ReadAsync()
C. GetMessage()
D. Receive()
Answer: A
What is the function of the WebSocketContext
class in ASP.NET Core?
A. To provide access to WebSocket connections and request information
B. To handle WebSocket message encoding
C. To manage server-side sessions
D. To perform URL routing
Answer: A
Which event is triggered when a WebSocket connection is closed?
A. OnClose
B. OnDisconnect
C. OnCloseAsync
D. OnEnd
Answer: C
How can you enable WebSocket support in an ASP.NET Core application?
A. By configuring WebSocket options in the Startup
class
B. By modifying the web.config
file
C. By using SignalR
only
D. By adding a WebSocketHandler
Answer: A
What does the WebSocket.ReceiveAsync
method return?
A. A ValueTask<WebSocketReceiveResult>
representing the result of the receive operation
B. A Task
representing the completion of the receive operation
C. A string
containing the received message
D. An int
representing the size of the received message
Answer: A
What is the purpose of the WebSocketReceiveResult
class?
A. To provide details about the received WebSocket message, such as its length and whether it is the final frame
B. To manage WebSocket connections
C. To handle WebSocket disconnections
D. To encode WebSocket messages
Answer: A
What does the WebSocketMessageType
enumeration represent?
A. The type of WebSocket message, such as text or binary
B. The status code of a WebSocket connection
C. The version of the WebSocket protocol
D. The type of HTTP request
Answer: A
How can you implement WebSocket-based real-time communication in an ASP.NET Core application?
A. By using the WebSocket
class and handling WebSocket events manually
B. By using only server-side HTTP controllers
C. By relying solely on SignalR
D. By using traditional polling techniques
Answer: A
What is a WebSocket handshake?
A. The process of establishing a WebSocket connection through an initial HTTP request and response
B. The process of closing a WebSocket connection
C. The process of sending a WebSocket message
D. The process of encoding WebSocket data
Answer: A
Which HTTP status code indicates a successful WebSocket upgrade request?
A. 101 Switching Protocols
B. 200 OK
C. 302 Found
D. 404 Not Found
Answer: A
What is the purpose of the SendAsync
method in the WebSocket class?
A. To send data over a WebSocket connection
B. To establish a WebSocket connection
C. To close a WebSocket connection
D. To receive data from a WebSocket connection
Answer: A
How can you handle WebSocket disconnections gracefully?
A. By implementing logic to handle the CloseAsync
method and cleanup resources
B. By ignoring disconnection events
C. By performing a full application restart
D. By using only traditional HTTP requests
Answer: A
What is a common challenge when working with WebSockets?
A. Managing connection stability and handling reconnections
B. Handling file uploads
C. Performing server-side authentication
D. Managing user sessions
Answer: A
Which class provides support for WebSockets in ASP.NET Core middleware?
A. WebSocketMiddleware
B. HttpContext
C. WebSocketOptions
D. Socket
Answer: A
What does the WebSocketOptions
class allow you to configure?
A. WebSocket connection settings such as buffer sizes and allowed origins
B. WebSocket message types
C. WebSocket authentication methods
D. WebSocket event handlers
Answer: A
What is the default behavior of the WebSocket ReceiveAsync
method if no data is available?
A. It will wait for data to arrive and block until data is received
B. It will return immediately with an empty result
C. It will close the WebSocket connection
D. It will throw an exception
Answer: A
How do you implement a WebSocket server in ASP.NET Core?
A. By adding WebSocket middleware to the Startup
class and configuring it in the Configure
method
B. By using the SignalR
library only
C. By modifying the web.config
file
D. By using a custom HTTP handler
Answer: A
What is the role of the HttpContext.WebSockets
property in ASP.NET Core?
A. To provide access to WebSocket connections for the current HTTP request
B. To handle HTTP requests
C. To manage session state
D. To encode WebSocket messages
Answer: A
Which method allows sending a binary message over a WebSocket connection?
A. SendAsync()
with WebSocketMessageType.Binary
B. SendBinary()
C. WriteBinary()
D. TransmitBinary()
Answer: A
How can you test WebSocket connections during development?
A. By using WebSocket clients or browser developer tools to connect and interact with WebSocket endpoints
B. By using traditional HTTP clients
C. By performing manual network traffic analysis
D. By using FTP clients
Answer: A
What is a typical use case for WebSockets in modern web applications?
A. Real-time chat applications and live notifications
B. File transfer and HTTP form submissions
C. Data persistence and state management
D. Server-side rendering and caching
Answer: A
Which class in ASP.NET Core represents the WebSocket connection for handling client communications?
A. WebSocket
B. HttpClient
C. WebSocketContext
D. HttpContext
Answer: A
How does WebSocket manage multiple concurrent connections in an ASP.NET Core application?
A. By maintaining separate WebSocket
instances for each connection
B. By using a single WebSocket
instance for all connections
C. By multiplexing connections over a single HttpClient
D. By handling connections through separate HTTP requests
Answer: A
What does the CloseStatus
property of WebSocketReceiveResult
indicate?
A. The reason for the WebSocket connection closure
B. The size of the received message
C. The type of WebSocket message
D. The timestamp of the message
Answer: A