by BehindJava

What are WebSockets and How is it different from HTTP

Home » java » What are WebSockets and How is it different from HTTP

In this tutorial, we are going to see how WebSockets are different from normal HTTP protocols.

How an HTTP protocol works

Let’s take an example, When a user hits google.com the request goes to the backend server in the form of an HTTP or HTTPS communication protocol which our browser uses to communicate with the webserver, and an appropriate response is returned. While a request is sent there will be a TCP connection created between the client and the server. Once the response is received connection gets closed.

What are WebSockets

Whenever a WebSocket is involved there will be a client and server similar to the HTTP. There is bidirectional communication between the WebSockets.

WebSockets are created using WS://, unlike HTTP. Whenever we see WS:// in a website means it is using WebSockets.

WS://www.google.com

The main difference between HTTP and WebSockets is HTTP is unidirectional while WebSocket is bidirectional which means the sender can send the data and also the receiver can send the data.

sdsds

The best example of a WebSocket is a chatting application. Once the connection is established by the user it stays until the user or server terminates the connection. WebSockets can be best used in real-time applications, gaming applications, and chat applications.