Top WebSockets frequently asked interview questions | JavaInUse



WebSocket Framework Interview Questions


In this post we will look at WebSocket Interview questions. Examples are provided with explanation.


Q: What is WebSockets?
A:
WebSocket is a computer communications protocol, providing full-duplex communication channels over a single TCP connection.

Q: What are the disadvantages of using traditional HTTP request response communication model?
A:
  • Traditional HTTP requests are unidirectional - In traditional client server communication, the client always initiates the request.
  • Half Duplex - User requests for a resource and the server then serves it to the client. The response is only sent after the request. So at a time only a single request occurs.
  • Multiple TCP connections - For each request a new TCPsession is needed to be established and then closed after receiving the response. So without using WebSockets we will have multiple sessions.
  • Heavy - Normal HTTP request and response require exchange of extra data between client and server.

Q: What are the advantages of using WebSockets over traditional HTTP communication?
A:
  • WebSocket are bi-directional - Using WebSocket either client or server can initiate sending a message.
  • WebSocket are Full Duplex - The client and server communication is independent of each other.
  • Single TCP connection - The initial connection is using HTTP, then this connection gets upgraded to a socket based connection. This single connection is then used for all the future communication
  • Light - The WebSocket message data exchange is much lighter compared to http.

Q: How to create a WebSocket connection?
A:

	ws = new WebSocket('ws://localhost:8080/user');


Q: Have you implemented WebSockets? What was the use case
A:
Have implemented WebSockets for a chat application using Spring Boot.
Spring Boot Web Socket

See Also

Spring Batch Interview Questions Apache Camel Interview Questions JBoss Fuse Interview Questions Drools Interview Questions Java 8 Interview Questions