What is WebSocket?
WebSocket is communication protocol that’s used in client-server communication. WebSocket is bidirectional and stateful protocol where the connection between client and server will keep alive until it is terminated by either client or server.
When the communication link is established and the connection is opened, it is possible to exchange messages in bidirectional way.
Use cases of WebSocket
- Real-time web application: shows the data at the client which is sent from the backend server.
- Gaming application: data continuously received by the server and it will appear on the screen without refreshing the UI.
- Chat application: used for exchange of data among the subscribers.
Difference between HTTP and Websocket
- HTTP is unidirectional whereas websocket is bidirectional.
- Each HTTP request establishes new connection to the server and after getting response, the connection gets terminated by itself. Connection established from websocket between client and server keeps alive until either client will terminate it.
- Websocket starts with
ws://
orwss://
.